TrinityCore
LogMessage.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 "LogMessage.h"
19#include "StringFormat.h"
20#include "Util.h"
21
22LogMessage::LogMessage(LogLevel _level, std::string_view _type, std::string _text)
23 : level(_level), type(_type), text(std::move(_text)), mtime(time(nullptr))
24{
25}
26
27LogMessage::LogMessage(LogLevel _level, std::string_view _type, std::string _text, std::string _param1)
28 : level(_level), type(_type), text(std::move(_text)), param1(std::move(_param1)), mtime(time(nullptr))
29{
30}
31
32std::string LogMessage::getTimeStr(time_t time)
33{
34 tm aTm;
35 localtime_r(&time, &aTm);
36 return Trinity::StringFormat("{:04}-{:02}-{:02}_{:02}:{:02}:{:02}", aTm.tm_year + 1900, aTm.tm_mon + 1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec);
37}
38
39std::string LogMessage::getTimeStr() const
40{
41 return getTimeStr(mtime);
42}
LogLevel
Definition: LogCommon.h:25
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
Definition: StringFormat.h:38
STL namespace.
LogMessage(LogLevel _level, std::string_view _type, std::string _text)
Definition: LogMessage.cpp:22
time_t mtime
Definition: LogMessage.h:42
std::string getTimeStr() const
Definition: LogMessage.cpp:39