TrinityCore
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
22Appender::Appender(uint8 _id, std::string _name, LogLevel _level /* = LOG_LEVEL_DISABLED */, AppenderFlags _flags /* = APPENDER_FLAGS_NONE */):
23id(_id), name(std::move(_name)), level(_level), flags(_flags) { }
24
25Appender::~Appender() = default;
26
28{
29 return id;
30}
31
32std::string const& Appender::getName() const
33{
34 return name;
35}
36
38{
39 return level;
40}
41
43{
44 return flags;
45}
46
48{
49 level = _level;
50}
51
53{
54 if (!level || level > message->level)
55 return;
56
58 {
59 message->prefix.reserve(100);
60 message->prefix.clear();
61
63 {
64 message->prefix.append(message->getTimeStr());
65 message->prefix.append(1, ' ');
66 }
67
69 Trinity::StringFormatTo(std::back_inserter(message->prefix), "{:<5} ", getLogLevelString(message->level));
70
72 {
73 message->prefix.append(1, '[');
74 message->prefix.append(message->type);
75 message->prefix.append("] ", 2);
76 }
77 }
78
79 _write(message);
80}
81
83{
84 switch (level)
85 {
86 case LOG_LEVEL_FATAL:
87 return "FATAL";
88 case LOG_LEVEL_ERROR:
89 return "ERROR";
90 case LOG_LEVEL_WARN:
91 return "WARN";
92 case LOG_LEVEL_INFO:
93 return "INFO";
94 case LOG_LEVEL_DEBUG:
95 return "DEBUG";
96 case LOG_LEVEL_TRACE:
97 return "TRACE";
98 default:
99 return "DISABLED";
100 }
101}
uint8_t uint8
Definition: Define.h:144
uint16 flags
Definition: DisableMgr.cpp:49
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:37
virtual void _write(LogMessage const *)=0
std::string name
Definition: Appender.h:53
uint8 id
Definition: Appender.h:52
LogLevel level
Definition: Appender.h:54
void write(LogMessage *message)
Definition: Appender.cpp:52
AppenderFlags getFlags() const
Definition: Appender.cpp:42
uint8 getId() const
Definition: Appender.cpp:27
virtual ~Appender()
std::string const & getName() const
Definition: Appender.cpp:32
static char const * getLogLevelString(LogLevel level)
Definition: Appender.cpp:82
AppenderFlags flags
Definition: Appender.h:55
Appender(uint8 _id, std::string name, LogLevel level=LOG_LEVEL_DISABLED, AppenderFlags flags=APPENDER_FLAGS_NONE)
Definition: Appender.cpp:22
void setLogLevel(LogLevel)
Definition: Appender.cpp:47
OutputIt StringFormatTo(OutputIt out, FormatString< Args... > fmt, Args &&... args)
Definition: StringFormat.h:51
STL namespace.
static std::string getTimeStr(time_t time)
Definition: LogMessage.cpp:32
LogLevel const level
Definition: LogMessage.h:37
std::string const type
Definition: LogMessage.h:38
std::string prefix
Definition: LogMessage.h:40