sculpto
logger.h
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file logger.h
3 * \brief Sculpto library logger implementation module.
4 *
5 * \author Sabitov Kirill
6 * \date 23 June 2022
7 *********************************************************************/
8
9#pragma once
10
11#include <string>
12
13#include "console_colors.h"
14#include "current_time.h"
15
16namespace scl
17{
19 class logger
20 {
21 private:
23 std::string Name = "";
25 std::ostream &Out = std::cout;
26
27 public:
28 /*!*
29 * Logger default constructor.
30 *
31 * \param Name - name of logger to be displayed at records.
32 */
33 logger(const std::string &Name = "");
34
35 public:
36 /*!*
37 * Log info message to current out stream.
38 *
39 * \param Message - message to log.
40 * \return None.
41 */
42 template <typename... Targs>
43 void Info(std::string_view Format, Targs&&... Args) const
44 {
45 Out <<
46 "[" << CurrentTime() << "] {|" << Name << "|} " <<
47 std::vformat(Format, std::make_format_args(Args...)) <<
48 '\n';
49 }
50
51 /*!*
52 * Log success message to current out stream.
53 *
54 * \param Message - message to log.
55 * \return None.
56 */
57 template <typename... Targs>
58 void Success(std::string_view Format, Targs&&... Args) const
59 {
60 Out <<
61 "[" << CurrentTime() << "] {|" << Name << "|} " <<
63 std::vformat(Format, std::make_format_args(Args...)) <<
65 }
66
67 /*!*
68 * Log warn message to current out stream.
69 *
70 * \param Message - message to log.
71 * \return None.
72 */
73 template <typename... Targs>
74 void Warn(std::string_view Format, Targs&&... Args) const
75 {
76 Out <<
77 "[" << CurrentTime() << "] {|" << Name << "|} " <<
79 std::vformat(Format, std::make_format_args(Args...)) <<
81 }
82
83 /*!*
84 * Log error message to current out stream.
85 *
86 * \param Message - message to log.
87 * \return None.
88 */
89 template <typename... Targs>
90 void Error(std::string_view Format, Targs&&... Args) const
91 {
92 Out <<
93 "[" << CurrentTime() << "] {|" << Name << "|} " <<
95 std::vformat(Format, std::make_format_args(Args...)) <<
97 }
98
99 /*!*
100 * Set currently using out stream.
101 *
102 * \param OutStream - new stream to log in.
103 * \return None.
104 */
105 void SetStream(std::ostream OutStream);
106 };
107}
void Warn(std::string_view Format, Targs &&... Args) const
Definition: logger.h:74
void Info(std::string_view Format, Targs &&... Args) const
Definition: logger.h:43
void Success(std::string_view Format, Targs &&... Args) const
Definition: logger.h:58
void SetStream(std::ostream OutStream)
Definition: logger.cpp:15
logger(const std::string &Name="")
Definition: logger.cpp:12
void Error(std::string_view Format, Targs &&... Args) const
Definition: logger.h:90
Helper to setting color of text in console implementation module.
const std::string color_literal_reset()
std::string color_literal(color ForegroundColor)
Definition: base.h:33
const std::string CurrentTime()
Definition: current_time.h:19