Fraxinus  16.5.0-fx-rc5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxLogMessage.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxLogMessage.h"
34 
35 #include "cxReporter.h"
36 #include "cxLogger.h"
37 #include <QtGlobal>
38 #include <iostream>
39 #include "boost/shared_ptr.hpp"
40 #include <QString>
41 #include <QMutex>
42 #include <QSound>
43 #include <QDir>
44 #include <QTextStream>
45 #include <QThread>
46 #include <QApplication>
47 #include "cxTypeConversions.h"
48 #include "cxDefinitionStrings.h"
49 #include "cxTime.h"
50 #include "cxMessageListener.h"
51 
52 namespace cx
53 {
54 
55 Message::Message(QString text, MESSAGE_LEVEL messageLevel, int timeoutTime) :
56  mText(text),
57  mMessageLevel(messageLevel),
58  mTimeoutTime(timeoutTime),
59  mTimeStamp(QDateTime::currentDateTime()),
60  mMuted(true),
61  mChannel("console")
62 {
63  this->setThreadName();
64 }
65 
67 {
68 
69 }
70 
71 void Message::setThreadName()
72 {
73  if (QApplication::instance()->thread() == QThread::currentThread())
74  mThread = "main";
75  else
76  {
77  mThread = QThread::currentThread()->objectName();
78  if (mThread.isEmpty())
79  mThread = "0x"+QString::number(reinterpret_cast<long>(QThread::currentThreadId()), 16);
80  }
81 }
82 
84 {
85  QString source = this->getSourceLocation();
86 
87  QString printableMessage;
88  if(mMessageLevel == mlRAW)
89  printableMessage = mText;
90  else
91  printableMessage = QString("[%1][%2] %3")
92  .arg(mTimeStamp.toString("hh:mm:ss.zzz"))
94  .arg(mText);
95 // printableMessage = QString("[%1][%2][%3][%4] %5")
96 // .arg(mTimeStamp.toString("hh:mm:ss.zzz"))
97 // .arg(source)
98 // .arg(mThread)
99 // .arg(qstring_cast(mMessageLevel))
100 // .arg(mText);
101 
102  return printableMessage;
103 }
104 
105 MESSAGE_LEVEL Message::getMessageLevel() const
106 {
107  return mMessageLevel;
108 }
109 
110 QString Message::getText() const
111 {
112  return mText;
113 }
114 
115 QDateTime Message::getTimeStamp() const
116 {
117  return mTimeStamp;
118 }
120 {
121  return mTimeoutTime;
122 }
124 {
125  if (mSourceFile.isEmpty() && mSourceFunction.isEmpty())
126  return "";
127  return QString("%1:%2/%3").arg(mSourceFile).arg(mSourceLine).arg(mSourceFunction);
128 }
129 
130 
131 } //End namespace cx
QString qstring_cast(const T &val)
mlRAW
Definition: cxDefinitions.h:82
QString mSourceFile
Definition: cxLogMessage.h:98
Message(QString text="", MESSAGE_LEVEL messageLevel=mlDEBUG, int timeoutTime=-1)
QString getPrintableMessage() const
Text containing information appropriate to display.
QString getText() const
The raw message.
int getTimeout() const
Timout tells the statusbar how long it should be displayed, this depends on the message level...
QString mThread
Definition: cxLogMessage.h:96
QDateTime getTimeStamp() const
The time at which the message was created.
MESSAGE_LEVEL mMessageLevel
Definition: cxLogMessage.h:90
QDateTime mTimeStamp
Definition: cxLogMessage.h:92
int mTimeoutTime
Definition: cxLogMessage.h:91
QString mSourceFunction
Definition: cxLogMessage.h:99
QString getSourceLocation() const
QString mText
Definition: cxLogMessage.h:89
MESSAGE_LEVEL getMessageLevel() const
The category of the message.