NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxLogger.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 
13 #include <QFileInfo>
14 
15 #include "cxLogger.h"
16 #include "cxReporter.h"
17 
18 namespace cx
19 {
20 
22 {
23 public:
24  std::stringstream stream;
26 };
27 
28 MessageLogger::MessageLogger(const char *file, int line, const char *function, const QString& channel, MESSAGE_LEVEL severity)
29 {
30  Message msg;
31  msg.mChannel = channel;
32  msg.mMessageLevel = severity;
33  msg.mTimeStamp = QDateTime::currentDateTime();
34  msg.mTimeoutTime = 3000;
35  msg.mSourceFile = file;
36  msg.mSourceLine = line;
37  msg.mSourceFunction = function;
38 
39  mInternalData.reset(new MessageLoggerInternalData);
40  mInternalData->msg = msg;
41 }
43 {
44  if (mInternalData.use_count()==1)
45  {
46  mInternalData->msg.mText = QString::fromStdString(mInternalData->stream.str());
47  reporter()->sendMessage(mInternalData->msg);
48  }
49 }
50 
52 {
53  return MessageLogger(*this);
54 }
55 
57 {
58  return MessageLogger(*this) << text;
59 }
60 
61 std::stringstream& MessageLogger::getStream()
62 {
63  return mInternalData->stream;
64 }
65 
66 
67 
68 void reportDebug(QString msg) { reporter()->sendDebug(msg); }
69 void report(QString msg) { reporter()->sendInfo(msg); }
70 void reportWarning(QString msg) { reporter()->sendWarning(msg); }
71 void reportError(QString msg) { reporter()->sendError(msg); }
72 void reportSuccess(QString msg) { reporter()->sendSuccess(msg); }
73 void reportVolatile(QString msg) { reporter()->sendVolatile(msg); }
74 
75 
76 }
cx::reportSuccess
void reportSuccess(QString msg)
Definition: cxLogger.cpp:72
cx::Message::mTimeStamp
QDateTime mTimeStamp
Definition: cxLogMessage.h:71
cx::MessageLoggerInternalData
Definition: cxLogger.cpp:21
cxLogger.h
cx::Message::mSourceFunction
QString mSourceFunction
Definition: cxLogMessage.h:78
cx::Message
Definition: cxLogMessage.h:54
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::reportDebug
void reportDebug(QString msg)
Definition: cxLogger.cpp:68
cx::report
void report(QString msg)
Definition: cxLogger.cpp:69
cx::Message::mChannel
QString mChannel
Definition: cxLogMessage.h:74
cxReporter.h
cx::reporter
ReporterPtr reporter()
Definition: cxReporter.cpp:36
cx::Message::mSourceLine
int mSourceLine
Definition: cxLogMessage.h:79
cx::MessageLogger::logger
MessageLogger logger() const
Definition: cxLogger.cpp:51
cx::Message::mMessageLevel
MESSAGE_LEVEL mMessageLevel
Definition: cxLogMessage.h:69
cx::MessageLogger::~MessageLogger
~MessageLogger()
Definition: cxLogger.cpp:42
cx::Message::mSourceFile
QString mSourceFile
Definition: cxLogMessage.h:77
cx::Message::mTimeoutTime
int mTimeoutTime
Definition: cxLogMessage.h:70
cx::MessageLogger
Definition: cxLogger.h:38
cx::MessageLoggerInternalData::stream
std::stringstream stream
Definition: cxLogger.cpp:24
cx::MessageLoggerInternalData::msg
Message msg
Definition: cxLogger.cpp:25
cx::MessageLogger::MessageLogger
MessageLogger(const char *file, int line, const char *function, const QString &channel, MESSAGE_LEVEL severity)
Definition: cxLogger.cpp:28
cx::reportError
void reportError(QString msg)
Definition: cxLogger.cpp:71
cx::reportVolatile
void reportVolatile(QString msg)
Definition: cxLogger.cpp:73
cx::reportWarning
void reportWarning(QString msg)
Definition: cxLogger.cpp:70