sptk2 logo
SPTK Home Page
Logger.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include "LogPriority.h"
30#include <sptk5/DateTime.h>
31#include <sptk5/sptk.h>
32
33namespace sptk {
34
35class LogEngine;
36
52class SP_EXPORT Logger
53{
54public:
58 struct Message {
59 DateTime timestamp {DateTime::Now()};
62
68 Message(LogPriority priority, String message);
69 };
70
71 using UMessage = std::shared_ptr<Message>;
72
78 Logger(LogEngine& destination, String prefix = "");
79
84 {
85 return m_destination;
86 }
87
93 void log(LogPriority priority, const String& message);
94
99 void debug(const String& message);
100
105 void info(const String& message);
106
111 void notice(const String& message);
112
117 void warning(const String& message);
118
123 void error(const String& message);
124
129 void critical(const String& message);
130
131private:
135 LogEngine& m_destination;
136 String m_prefix;
137};
138
139using SLogger = std::shared_ptr<Logger>;
140
144} // namespace sptk
Definition: DateTime.h:86
static DateTime Now()
Definition: LogEngine.h:60
A log that sends all the log messages into another log.
Definition: Logger.h:53
LogEngine & destination()
Returns log engine (destination logger)
Definition: Logger.h:83
void warning(const String &message)
void critical(const String &message)
void log(LogPriority priority, const String &message)
void error(const String &message)
Logger(LogEngine &destination, String prefix="")
Constructor.
void info(const String &message)
void debug(const String &message)
void notice(const String &message)
Definition: String.h:49
LogPriority
Log message priority.
Definition: LogPriority.h:68
Definition: Logger.h:58
String message
Message text.
Definition: Logger.h:61
Message(LogPriority priority, String message)
LogPriority priority
Message priority.
Definition: Logger.h:60

Fri Oct 14 2022 09:58:31: SPTK 5.4.1