NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxLogMessage.h"
13 
14 #include "cxReporter.h"
15 #include "cxLogger.h"
16 #include <QtGlobal>
17 #include <iostream>
18 #include "boost/shared_ptr.hpp"
19 #include <QString>
20 #include <QMutex>
21 #include <QSound>
22 #include <QDir>
23 #include <QTextStream>
24 #include <QThread>
25 #include <QApplication>
26 #include "cxTypeConversions.h"
27 #include "cxTime.h"
28 #include "cxMessageListener.h"
29 
30 namespace cx
31 {
32 
33 Message::Message(QString text, MESSAGE_LEVEL messageLevel, int timeoutTime) :
34  mText(text),
35  mMessageLevel(messageLevel),
36  mTimeoutTime(timeoutTime),
37  mTimeStamp(QDateTime::currentDateTime()),
38  mMuted(true),
39  mChannel("console")
40 {
41  mThread = "NotUsed";
42  //this->setThreadName(); //Cause crash on Ubuntu 20.04, when calling QApplication::instance()->thread()
43 }
44 
46 {
47 
48 }
49 
50 void Message::setThreadName()
51 {
52  if (QApplication::instance()->thread() == QThread::currentThread())
53  mThread = "main";
54  else
55  {
56  mThread = QThread::currentThread()->objectName();
57  if (mThread.isEmpty())
58  mThread = "0x"+QString::number(reinterpret_cast<long>(QThread::currentThreadId()), 16);
59  }
60 }
61 
63 {
64  QString source = this->getSourceLocation();
65 
66  QString printableMessage;
67  if(mMessageLevel == mlRAW)
68  printableMessage = mText;
69  else
70  printableMessage = QString("[%1][%2] %3")
71  .arg(mTimeStamp.toString("hh:mm:ss.zzz"))
73  .arg(mText);
74 // printableMessage = QString("[%1][%2][%3][%4] %5")
75 // .arg(mTimeStamp.toString("hh:mm:ss.zzz"))
76 // .arg(source)
77 // .arg(mThread)
78 // .arg(qstring_cast(mMessageLevel))
79 // .arg(mText);
80 
81  return printableMessage;
82 }
83 
84 MESSAGE_LEVEL Message::getMessageLevel() const
85 {
86  return mMessageLevel;
87 }
88 
89 QString Message::getText() const
90 {
91  return mText;
92 }
93 
94 QDateTime Message::getTimeStamp() const
95 {
96  return mTimeStamp;
97 }
99 {
100  return mTimeoutTime;
101 }
103 {
104  if (mSourceFile.isEmpty() && mSourceFunction.isEmpty())
105  return "";
106  return QString("%1:%2/%3").arg(mSourceFile).arg(mSourceLine).arg(mSourceFunction);
107 }
108 
109 
110 } //End namespace cx
cx::Message::mTimeStamp
QDateTime mTimeStamp
Definition: cxLogMessage.h:71
cxLogger.h
cxMessageListener.h
qstring_cast
QString qstring_cast(const T &val)
Definition: cxTypeConversions.h:46
cx::Message::mSourceFunction
QString mSourceFunction
Definition: cxLogMessage.h:78
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::Message::mThread
QString mThread
Definition: cxLogMessage.h:75
cx::Message::getMessageLevel
MESSAGE_LEVEL getMessageLevel() const
The category of the message.
Definition: cxLogMessage.cpp:84
cxLogMessage.h
cxReporter.h
mlRAW
mlRAW
Definition: cxDefinitions.h:75
cx::Message::mSourceLine
int mSourceLine
Definition: cxLogMessage.h:79
cx::Message::mMessageLevel
MESSAGE_LEVEL mMessageLevel
Definition: cxLogMessage.h:69
cx::Message::getPrintableMessage
QString getPrintableMessage() const
Text containing information appropriate to display.
Definition: cxLogMessage.cpp:62
cxTypeConversions.h
cx::Message::mSourceFile
QString mSourceFile
Definition: cxLogMessage.h:77
cx::Message::mTimeoutTime
int mTimeoutTime
Definition: cxLogMessage.h:70
cx::Message::getTimeout
int getTimeout() const
Timout tells the statusbar how long it should be displayed, this depends on the message level.
Definition: cxLogMessage.cpp:98
cx::Message::getSourceLocation
QString getSourceLocation() const
Definition: cxLogMessage.cpp:102
cx::Message::~Message
~Message()
Definition: cxLogMessage.cpp:45
cx::Message::Message
Message(QString text="", MESSAGE_LEVEL messageLevel=mlDEBUG, int timeoutTime=-1)
Definition: cxLogMessage.cpp:33
cx::Message::mText
QString mText
Definition: cxLogMessage.h:68
cxTime.h
cx::Message::getText
QString getText() const
The raw message.
Definition: cxLogMessage.cpp:89
cx::Message::getTimeStamp
QDateTime getTimeStamp() const
The time at which the message was created.
Definition: cxLogMessage.cpp:94