VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
Logger.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
30//=======================================================================================
31#include "Logger.h"
32
33#include <spdlog/sinks/basic_file_sink.h>
34#include <spdlog/sinks/daily_file_sink.h>
35#include <spdlog/sinks/stdout_color_sinks.h>
36#include <spdlog/spdlog.h>
37
38namespace vf::logging
39{
40
41std::string Logger::logPath = { "logs/" };
42
44{
45 updateDefaultLogger();
46
47 // setting default log level to trace
48 // levels: trace < debug < info < warn < error < critical
49 spdlog::set_level(spdlog::level::trace);
50
51 // setting the log pattern
52 // formatting is documented here: https://github.com/gabime/spdlog/wiki/3.-Custom-formatting
53 spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] %v");
54
55 // according to the flush policy https://github.com/gabime/spdlog/wiki/7.-Flush-policy
56 spdlog::flush_on(spdlog::level::info);
57}
58
59void Logger::changeLogPath(std::string path)
60{
61 if(path.back() != '/')
62 path.append("/");
63
64 logPath = path;
65
66 updateDefaultLogger();
67}
68
69void Logger::updateDefaultLogger()
70{
71 // initialize stdout sink with colored output
72 auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
73
74 // initialize daily file sink
75 // files will be written into "logs" folder relative to pwd. A new files is created at 0:00 o'clock.
76 auto daily_file_sink = std::make_shared<spdlog::sinks::daily_file_sink_mt>(logPath + "daily.txt", 0, 0);
77
78 // initialize last run file sink
79 auto last_run_file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(logPath + "last_run.txt", true);
80
81 // creating default logger with console and file sink
82 spdlog::set_default_logger(std::make_shared<spdlog::logger>(
83 "default", spdlog::sinks_init_list({ console_sink, daily_file_sink, last_run_file_sink })));
84}
85
86} // namespace vf::logging
static void initializeLogger()
Definition Logger.cpp:43
static void changeLogPath(std::string path)
Definition Logger.cpp:59
std::shared_ptr< T > SPtr