Doxygen
Toggle main menu visibility
Loading...
Searching...
No Matches
trace.cpp
Go to the documentation of this file.
1
/******************************************************************************
2
*
3
* Copyright (C) 1997-2023 by Dimitri van Heesch.
4
*
5
* Permission to use, copy, modify, and distribute this software and its
6
* documentation under the terms of the GNU General Public License is hereby
7
* granted. No representations are made about the suitability of this software
8
* for any purpose. It is provided "as is" without express or implied warranty.
9
* See the GNU General Public License for more details.
10
*
11
* Documents produced by Doxygen are derivative works derived from the
12
* input used in their production; they are not affected by this license.
13
*
14
*/
15
16
// own header
17
#include "
trace.h
"
18
19
// other includes
20
#include "spdlog/sinks/basic_file_sink.h"
// support for basic file logging
21
#include "spdlog/sinks/stdout_sinks.h"
22
23
std::shared_ptr<spdlog::logger>
g_tracer
;
24
25
void
initTracing
(
const
DString
&logFile,
bool
timing)
26
{
27
if
(!logFile.
empty
())
28
{
29
std::vector<spdlog::sink_ptr> sinks;
30
if
(logFile==
"stdout"
)
31
{
32
sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
33
}
34
else
if
(logFile==
"stderr"
)
35
{
36
sinks.push_back(std::make_shared<spdlog::sinks::stderr_sink_mt>());
37
}
38
else
// normal file
39
{
40
sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(logFile.
str
(),
true
));
41
}
42
g_tracer
= std::make_shared<spdlog::logger>(
"tracing"
, sinks.begin(),sinks.end());
43
g_tracer
->set_level(spdlog::level::trace);
44
if
(timing)
45
{
46
g_tracer
->set_pattern(
"[%C-%m-%d %T.%e][%t][%s:%#](%!) %v"
);
47
}
48
else
49
{
50
g_tracer
->set_pattern(
"[%s:%#](%!) %v"
);
51
}
52
}
53
}
54
55
void
exitTracing
()
56
{
57
if
(
g_tracer
)
58
{
59
spdlog::shutdown();
60
}
61
}
62
DString
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition
dstring.h:84
DString::empty
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition
dstring.h:148
DString::str
const std::string & str() const
Definition
dstring.h:645
exitTracing
void exitTracing()
Definition
trace.cpp:55
initTracing
void initTracing(const DString &logFile, bool timing)
Definition
trace.cpp:25
g_tracer
std::shared_ptr< spdlog::logger > g_tracer
Definition
trace.cpp:23
trace.h
src
trace.cpp
Generated by
1.19.0