TrinityCore
AppenderDB.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 "AppenderDB.h"
19#include "DatabaseEnv.h"
20#include "LogMessage.h"
21#include "PreparedStatement.h"
22
23AppenderDB::AppenderDB(uint8 id, std::string const& name, LogLevel level, AppenderFlags /*flags*/, std::vector<std::string_view> const& /*args*/)
24 : Appender(id, name, level), realmId(0), enabled(false) { }
25
27
28void AppenderDB::_write(LogMessage const* message)
29{
30 // Avoid infinite loop, PExecute triggers Logging with "sql.sql" type
31 if (!enabled || (message->type.find("sql") != std::string::npos))
32 return;
33
35 stmt->setUInt64(0, message->mtime);
36 stmt->setUInt32(1, realmId);
37 stmt->setString(2, message->type);
38 stmt->setUInt8(3, uint8(message->level));
39 stmt->setString(4, message->text);
40 LoginDatabase.Execute(stmt);
41}
42
44{
45 enabled = true;
46 realmId = _realmId;
47}
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
uint8_t uint8
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:142
AppenderFlags
Definition: LogCommon.h:50
LogLevel
Definition: LogCommon.h:25
@ LOGIN_INS_LOG
Definition: LoginDatabase.h:63
bool enabled
Definition: AppenderDB.h:36
uint32 realmId
Definition: AppenderDB.h:35
void setRealmId(uint32 realmId) override
Definition: AppenderDB.cpp:43
void _write(LogMessage const *message) override
Definition: AppenderDB.cpp:28
AppenderDB(uint8 id, std::string const &name, LogLevel level, AppenderFlags flags, std::vector< std::string_view > const &args)
Definition: AppenderDB.cpp:23
void setUInt8(const uint8 index, const uint8 value)
void setUInt32(const uint8 index, const uint32 value)
void setString(const uint8 index, const std::string &value)
void setUInt64(const uint8 index, const uint64 value)
LogLevel const level
Definition: LogMessage.h:37
std::string const text
Definition: LogMessage.h:39
time_t mtime
Definition: LogMessage.h:42
std::string const type
Definition: LogMessage.h:38