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#include <sstream>
22
23Appender::Appender(uint8 _id, std::string const& _name, LogLevel _level /* = LOG_LEVEL_DISABLED */, AppenderFlags _flags /* = APPENDER_FLAGS_NONE */):
24id(_id), name(_name), level(_level), flags(_flags) { }
25
27
29{
30 return id;
31}
32
33std::string const& Appender::getName() const
34{
35 return name;
36}
37
39{
40 return level;
41}
42
44{
45 return flags;
46}
47
49{
50 level = _level;
51}
52
54{
55 if (!level || level > message->level)
56 return;
57
58 std::ostringstream ss;
59
61 ss << message->getTimeStr() << ' ';
62
65
67 ss << '[' << message->type << "] ";
68
69 message->prefix = ss.str();
70 _write(message);
71}
72
74{
75 switch (level)
76 {
77 case LOG_LEVEL_FATAL:
78 return "FATAL";
79 case LOG_LEVEL_ERROR:
80 return "ERROR";
81 case LOG_LEVEL_WARN:
82 return "WARN";
83 case LOG_LEVEL_INFO:
84 return "INFO";
85 case LOG_LEVEL_DEBUG:
86 return "DEBUG";
87 case LOG_LEVEL_TRACE:
88 return "TRACE";
89 default:
90 return "DISABLED";
91 }
92}
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:38
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:53
AppenderFlags getFlags() const
Definition: Appender.cpp:43
uint8 getId() const
Definition: Appender.cpp:28
virtual ~Appender()
Definition: Appender.cpp:26
std::string const & getName() const
Definition: Appender.cpp:33
static char const * getLogLevelString(LogLevel level)
Definition: Appender.cpp:73
AppenderFlags flags
Definition: Appender.h:52
void setLogLevel(LogLevel)
Definition: Appender.cpp:48
Appender(uint8 _id, std::string const &name, LogLevel level=LOG_LEVEL_DISABLED, AppenderFlags flags=APPENDER_FLAGS_NONE)
Definition: Appender.cpp:23
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
Definition: StringFormat.h:38
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