Doxygen
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
20std::shared_ptr<spdlog::logger> g_tracer;
21
22void initTracing(const QCString &logFile, bool timing)
23{
24 if (!logFile.isEmpty())
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
53{
54 if (g_tracer)
55 {
56 spdlog::shutdown();
57 }
58}
59
This is an alternative implementation of QCString.
Definition qcstring.h:101
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const std::string & str() const
Definition qcstring.h:526
void exitTracing()
Definition trace.cpp:52
std::shared_ptr< spdlog::logger > g_tracer
Definition trace.cpp:20
void initTracing(const QCString &logFile, bool timing)
Definition trace.cpp:22