-
Notifications
You must be signed in to change notification settings - Fork 62
/
logging.cpp
112 lines (90 loc) · 3.62 KB
/
logging.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*************************************************************************************
Copyright (C) 2014 Laboratori de Gràfics i Imatge, Universitat de Girona &
Institut de Diagnòstic per la Imatge.
Girona 2014. All rights reserved.
http:https://starviewer.udg.edu
This file is part of the Starviewer (Medical Imaging Software) open source project.
It is subject to the license terms in the LICENSE file found in the top-level
directory of this distribution and at http:https://starviewer.udg.edu/license. No part of
the Starviewer (Medical Imaging Software) open source project, including this file,
may be copied, modified, propagated, or distributed except according to the
terms contained in the LICENSE file.
*************************************************************************************/
#include "logging.h"
#include "easylogging++.h"
#include "starviewerapplication.h"
#include <QApplication>
namespace udg {
void beginLogging()
{
// Primer comprovem que existeixi el direcotori ~/.starviewer/log/ on guradarem els logs
QDir logDir = udg::UserLogsPath;
if (!logDir.exists())
{
// Creem el directori
logDir.mkpath(udg::UserLogsPath);
}
el::Configurations logConfig(getLogConfFilePath().toStdString());
logConfig.setGlobally(el::ConfigurationType::Filename, getLogFilePath().toStdString());
//Disable logging to the standard output when compiled on release
#ifdef QT_NO_DEBUG
logConfig.setGlobally(el::ConfigurationType::ToStandardOutput, "false");
#endif
el::Loggers::reconfigureAllLoggers(logConfig);
}
QString getLogFilePath()
{
return QDir::toNativeSeparators(udg::UserLogsFile);
}
QString getLogConfFilePath()
{
// TODO donem per fet que l'arxiu es diu així i es troba a la localització que indiquem. S'hauria de fer una mica més flexible o genèric;
// està així perquè de moment volem anar per feina i no entretenir-nos però s'ha de fer bé.
QString configurationFile;
if (qApp->applicationFilePath().contains("autotests"))
{
configurationFile = sourcePath() + "/tests/auto/log.conf";
}
else
{
configurationFile = "/etc/starviewer/log.conf";
if (!QFile::exists(configurationFile))
{
configurationFile = installationPath() + "/log.conf";
}
if (!QFile::exists(configurationFile))
{
configurationFile = sourcePath() + "/bin/log.conf";
}
}
return configurationFile;
}
void debugLog(const QString &msg, const QString &file, int line, const QString &function)
{
LOG(DEBUG) << qPrintable(QString("%1 [ %2:%3 %4 ]").arg(msg, file, QString::number(line), function));
}
void infoLog(const QString &msg, const QString&, int, const QString&)
{
LOG(INFO) << qUtf8Printable(msg);
}
void warnLog(const QString &msg, const QString &file, int line, const QString &function)
{
LOG(WARNING) << qUtf8Printable(QString("%1 [ %2:%3 %4 ]").arg(msg, file, QString::number(line), function));
}
void errorLog(const QString &msg, const QString &file, int line, const QString &function)
{
LOG(ERROR) << qUtf8Printable(QString("%1 [ %2:%3 %4 ]").arg(msg, file, QString::number(line), function));
}
void fatalLog(const QString &msg, const QString &file, int line, const QString &function)
{
LOG(FATAL) << qUtf8Printable(QString("%1 [ %2:%3 %4 ]").arg(msg, file, QString::number(line), function));
}
void verboseLog(int vLevel, const QString &msg, const QString&, int, const QString&)
{
VLOG(vLevel) << qUtf8Printable(msg);
}
void traceLog(const QString &msg, const QString&, int, const QString&)
{
LOG(TRACE) << qUtf8Printable(msg);
}
}