Legends-of-Azeroth-Pandaria-5.4.8
93 строки · 2.3 Кб
1/*
2* This file is part of the Pandaria 5.4.8 Project. See THANKS 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
27Appender::~Appender() { }
28
29uint8 Appender::getId() const
30{
31return id;
32}
33
34std::string const& Appender::getName() const
35{
36return name;
37}
38
39LogLevel Appender::getLogLevel() const
40{
41return level;
42}
43
44AppenderFlags Appender::getFlags() const
45{
46return flags;
47}
48
49void Appender::setLogLevel(LogLevel _level)
50{
51level = _level;
52}
53
54void Appender::write(LogMessage* message)
55{
56if (!level || level > message->level)
57return;
58
59std::ostringstream ss;
60
61if (flags & APPENDER_FLAGS_PREFIX_TIMESTAMP)
62ss << message->getTimeStr() << ' ';
63
64if (flags & APPENDER_FLAGS_PREFIX_LOGLEVEL)
65ss << Trinity::StringFormat("%-5s ", Appender::getLogLevelString(message->level));
66
67if (flags & APPENDER_FLAGS_PREFIX_LOGFILTERTYPE)
68ss << '[' << message->type << "] ";
69
70message->prefix = ss.str();
71_write(message);
72}
73
74char const* Appender::getLogLevelString(LogLevel level)
75{
76switch (level)
77{
78case LOG_LEVEL_FATAL:
79return "FATAL";
80case LOG_LEVEL_ERROR:
81return "ERROR";
82case LOG_LEVEL_WARN:
83return "WARN";
84case LOG_LEVEL_INFO:
85return "INFO";
86case LOG_LEVEL_DEBUG:
87return "DEBUG";
88case LOG_LEVEL_TRACE:
89return "TRACE";
90default:
91return "DISABLED";
92}
93}
94