TrinityCore
Loading...
Searching...
No Matches
Appender.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "Appender.h"
19#include "LogMessage.h"
20#include "StringFormat.h"
21
22#include <sstream>
23
24Appender::Appender(uint8 _id, std::string const& _name, LogLevel _level /* = LOG_LEVEL_DISABLED */, AppenderFlags _flags /* = APPENDER_FLAGS_NONE */):
25id(_id), name(_name), level(_level), flags(_flags) { }
26
28
30{
31 return id;
32}
33
34std::string const& Appender::getName() const
35{
36 return name;
37}
38
40{
41 return level;
42}
43
45{
46 return flags;
47}
48
50{
51 level = _level;
52}
53
55{
56 if (!level || level > message->level)
57 return;
58
59 std::ostringstream ss;
60
62 ss << message->getTimeStr() << ' ';
63
66
68 ss << '[' << message->type << "] ";
69
70 message->prefix = ss.str();
71 _write(message);
72}
73
75{
76 switch (level)
77 {
78 case LOG_LEVEL_FATAL:
79 return "FATAL";
80 case LOG_LEVEL_ERROR:
81 return "ERROR";
82 case LOG_LEVEL_WARN:
83 return "WARN";
84 case LOG_LEVEL_INFO:
85 return "INFO";
86 case LOG_LEVEL_DEBUG:
87 return "DEBUG";
88 case LOG_LEVEL_TRACE:
89 return "TRACE";
90 default:
91 return "DISABLED";
92 }
93}
uint8_t uint8
Definition Define.h:135
uint16 flags
AppenderFlags
Definition LogCommon.h:50
@ APPENDER_FLAGS_PREFIX_TIMESTAMP
Definition LogCommon.h:52
@ APPENDER_FLAGS_PREFIX_LOGFILTERTYPE
Definition LogCommon.h:54
@ APPENDER_FLAGS_PREFIX_LOGLEVEL
Definition LogCommon.h:53
LogLevel
Definition LogCommon.h:25
@ LOG_LEVEL_DEBUG
Definition LogCommon.h:28
@ LOG_LEVEL_ERROR
Definition LogCommon.h:31
@ LOG_LEVEL_FATAL
Definition LogCommon.h:32
@ LOG_LEVEL_TRACE
Definition LogCommon.h:27
@ LOG_LEVEL_WARN
Definition LogCommon.h:30
@ LOG_LEVEL_INFO
Definition LogCommon.h:29
LogLevel getLogLevel() const
Definition Appender.cpp:39
virtual void _write(LogMessage const *)=0
std::string name
Definition Appender.h:50
uint8 id
Definition Appender.h:49
LogLevel level
Definition Appender.h:51
void write(LogMessage *message)
Definition Appender.cpp:54
AppenderFlags getFlags() const
Definition Appender.cpp:44
uint8 getId() const
Definition Appender.cpp:29
virtual ~Appender()
Definition Appender.cpp:27
std::string const & getName() const
Definition Appender.cpp:34
static char const * getLogLevelString(LogLevel level)
Definition Appender.cpp:74
AppenderFlags flags
Definition Appender.h:52
void setLogLevel(LogLevel)
Definition Appender.cpp:49
Appender(uint8 _id, std::string const &name, LogLevel level=LOG_LEVEL_DISABLED, AppenderFlags flags=APPENDER_FLAGS_NONE)
Definition Appender.cpp:24
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
static std::string getTimeStr(time_t time)
LogLevel const level
Definition LogMessage.h:37
std::string const type
Definition LogMessage.h:38
std::string prefix
Definition LogMessage.h:40