]> vaikene.ee Git - evaf/blob - src/libs/Common/logger.cpp
More work on the common library and the main GUI application.
[evaf] / src / libs / Common / logger.cpp
1 /**
2 * @file Common/logger.cpp
3 * @brief iLogger interface implementation
4 * @author Enar Vaikene
5 *
6 * Copyright (c) 2011 Enar Vaikene
7 *
8 * This file is part of the eVaf C++ cross-platform application development framework.
9 *
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
15 *
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
18 */
19
20 #include "logger.h"
21 #include "iregistry.h"
22 #include "ienv.h"
23
24 #include <QtCore>
25
26 #ifdef Q_OS_WIN32
27 # include <windows.h>
28 #endif
29
30 #ifdef Q_OS_LINUX
31 # include <stdio.h>
32 # include <stdarg.h>
33 # include <stdlib.h>
34 #endif
35
36
37 //-------------------------------------------------------------------
38
39 using namespace eVaf::Common;
40
41 iLogger * iLogger::instance()
42 {
43 static Internal::Logger singleton;
44 return &singleton;
45 }
46
47
48 //-------------------------------------------------------------------
49
50 using namespace eVaf::Common::Internal;
51
52 void defFatalMsgHandler(QString const & msg, QString const & source, QString const & where)
53 {
54 Q_UNUSED(source);
55
56 fprintf(stderr, "FATAL ERROR: %s (occurred in %s)\n", qPrintable(msg), qPrintable(where));
57
58 #ifdef Q_OS_LINUX
59 abort();
60 #else
61 exit(1);
62 #endif
63 }
64
65
66 //-------------------------------------------------------------------
67
68 LoggerSource::LoggerSource()
69 : QSharedData()
70 , severity(iLogger::Fatal)
71 , maxSize(100 * 1024)
72 , maxCount(3)
73 {}
74
75 LoggerSource::LoggerSource(LoggerSource const & o)
76 : QSharedData()
77 , severity(o.severity)
78 , maxSize(o.maxSize)
79 , maxCount(o.maxCount)
80 {}
81
82 void LoggerSource::init(QString const & source, QString const & logDir, QString const & etcDir)
83 {
84 Q_UNUSED(etcDir);
85
86 fileName = logDir + source + ".log";
87 }
88
89
90 //-------------------------------------------------------------------