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
#include "
trace.h
"
17
#include "spdlog/sinks/basic_file_sink.h"
// support for basic file logging
18
#include "spdlog/sinks/stdout_sinks.h"
19
20
std::shared_ptr<spdlog::logger>
g_tracer
;
21
22
void
initTracing
(
const
DString
&logFile,
bool
timing)
23
{
24
if
(!logFile.
empty
())
25
{
26
std::vector<spdlog::sink_ptr> sinks;
27
if
(logFile==
"stdout"
)
28
{
29
sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
30
}
31
else
if
(logFile==
"stderr"
)
32
{
33
sinks.push_back(std::make_shared<spdlog::sinks::stderr_sink_mt>());
34
}
35
else
// normal file
36
{
37
sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(logFile.
str
(),
true
));
38
}
39
g_tracer
= std::make_shared<spdlog::logger>(
"tracing"
, sinks.begin(),sinks.end());
40
g_tracer
->set_level(spdlog::level::trace);
41
if
(timing)
42
{
43
g_tracer
->set_pattern(
"[%C-%m-%d %T.%e][%t][%s:%#](%!) %v"
);
44
}
45
else
46
{
47
g_tracer
->set_pattern(
"[%s:%#](%!) %v"
);
48
}
49
}
50
}
51
52
void
exitTracing
()
53
{
54
if
(
g_tracer
)
55
{
56
spdlog::shutdown();
57
}
58
}
59
DString
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition
dstring.h:88
DString::empty
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition
dstring.h:152
DString::str
const std::string & str() const
Definition
dstring.h:649
exitTracing
void exitTracing()
Definition
trace.cpp:52
initTracing
void initTracing(const DString &logFile, bool timing)
Definition
trace.cpp:22
g_tracer
std::shared_ptr< spdlog::logger > g_tracer
Definition
trace.cpp:20
trace.h
src
trace.cpp
Generated by
1.19.0