Legends-of-Azeroth-Pandaria-5.4.8

Форк
0
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

24
Appender::Appender(uint8 _id, std::string const& _name, LogLevel _level /* = LOG_LEVEL_DISABLED */, AppenderFlags _flags /* = APPENDER_FLAGS_NONE */):
25
id(_id), name(_name), level(_level), flags(_flags) { }
26

27
Appender::~Appender() { }
28

29
uint8 Appender::getId() const
30
{
31
    return id;
32
}
33

34
std::string const& Appender::getName() const
35
{
36
    return name;
37
}
38

39
LogLevel Appender::getLogLevel() const
40
{
41
    return level;
42
}
43

44
AppenderFlags Appender::getFlags() const
45
{
46
    return flags;
47
}
48

49
void Appender::setLogLevel(LogLevel _level)
50
{
51
    level = _level;
52
}
53

54
void Appender::write(LogMessage* message)
55
{
56
    if (!level || level > message->level)
57
        return;
58

59
    std::ostringstream ss;
60

61
    if (flags & APPENDER_FLAGS_PREFIX_TIMESTAMP)
62
        ss << message->getTimeStr() << ' ';
63

64
    if (flags & APPENDER_FLAGS_PREFIX_LOGLEVEL)
65
        ss << Trinity::StringFormat("%-5s ", Appender::getLogLevelString(message->level));
66

67
    if (flags & APPENDER_FLAGS_PREFIX_LOGFILTERTYPE)
68
        ss << '[' << message->type << "] ";
69

70
    message->prefix = ss.str();
71
    _write(message);
72
}
73

74
char const* Appender::getLogLevelString(LogLevel level)
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
}
94

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.