Fraxinus  22.09
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 }
void reportError(QString msg)
Definition: cxLogger.cpp:71
QString mSourceFile
Definition: cxLogMessage.h:77
void reportVolatile(QString msg)
Definition: cxLogger.cpp:73
ReporterPtr reporter()
Definition: cxReporter.cpp:36
MESSAGE_LEVEL mMessageLevel
Definition: cxLogMessage.h:69
MessageLogger logger() const
Definition: cxLogger.cpp:51
QString mChannel
Definition: cxLogMessage.h:74
void reportWarning(QString msg)
Definition: cxLogger.cpp:70
void reportSuccess(QString msg)
Definition: cxLogger.cpp:72
QDateTime mTimeStamp
Definition: cxLogMessage.h:71
int mTimeoutTime
Definition: cxLogMessage.h:70
QString mSourceFunction
Definition: cxLogMessage.h:78
void report(QString msg)
Definition: cxLogger.cpp:69
MessageLogger(const char *file, int line, const char *function, const QString &channel, MESSAGE_LEVEL severity)
Definition: cxLogger.cpp:28
void reportDebug(QString msg)
Definition: cxLogger.cpp:68
std::stringstream stream
Definition: cxLogger.cpp:24
Namespace for all CustusX production code.