From 55ce180f2867700b28921d99f9a0cb9c83330c91 Mon Sep 17 00:00:00 2001 From: Spp Date: Fri, 3 Aug 2012 14:20:18 +0200 Subject: Core/Logging: Add Asyncronous logging with Loggers ("What to log") and Appenders ("Where to log") system. Will allow to select to full log some parts of core while others are not even logged. - Logging System is asyncronous to improve performance. - Each msg and Logger has a Log Type and Log Level assigned. Each msg is assigned the Logger of same Log Type or "root" Logger is selected if there is no Logger configured for the given Log Type - Loggers have a list of Appenders to send the msg to. The Msg in the Logger is not sent to Appenders if the msg LogLevel is lower than Logger LogLevel. - There are three (at the moment) types of Appenders: Console, File or DB (this is WIP, not working ATM). Msg is not written to the resource if msg LogLevel is lower than Appender LogLevel. - Appender and Console Log levels can be changed while server is active with command '.set loglevel (a/l) name level' Explanation of use with Sample config: Appender.Console.Type=1 (1 = Console) Appender.Console.Level=2 (2 = Debug) Appender.Server.Type=2 (2 = File) Appender.Server.Level=3 (3 = Info) Appender.Server.File=Server.log Appender.SQL.Type=2 (2 = File) Appender.SQL.Level=1 (1 = Trace) Appender.SQL.File=sql.log Appenders=Console Server (NOTE: SQL has not been included here... that will make core ignore the config for "SQL" as it's not in this list) Logger.root.Type=0 (0 = Default - if it's not created by config, server will create it with LogLevel = DISABLED) Logger.root.Level=5 (5 = Error) Logger.root.Appenders=Console Logger.SQL.Type=26 (26 = SQL) Logger.SQL.Level=3 (2 = Debug) Logger.SQL.Appenders=Console Server SQL Logger.SomeRandomName.Type=24 (24 = Guild) Logger.SomeRandomName.Level=5 (5 = Error) Loggers=root SQL SomeRandomName * At loading Appender SQL will be ignored, as it's not present on "Appenders" * sLog->outDebug(LOG_FILTER_GUILD, "Some log msg related to Guilds") - Msg is sent to Logger of Type LOG_FILTER_GUILD (24). Logger with name SomeRandomName is found but it's LogLevel = 5 and Msg LogLevel=2... Msg is not logged * sLog->outError(LOG_FILTER_GUILD, "Some error log msg related to Guilds") - Msg is sent to Logger of Type LOG_FILTER_GUILD (24). Logger with name SomeRandomeName is found with proper LogLevel but Logger does not have any Appenders assigned to that logger... Msg is not logged * sLog->outDebug(LOG_FILTER_SQL, "Some msg related to SQLs") - Msg is sent to Logger SQL (matches type), as it matches LogLevel the msg is sent to Appenders Console, Server and SQL - Appender Console has lower Log Level: Msg is logged to Console - Appender Server has higher Log Level: Msg is not logged to file - Appender SQL has lower Log Level: Msg is logged to file sql.log * sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Some msg related to Battelgrounds") - Msg is sent to Logger root (Type 0) as no Logger was found with Type LOG_FILTER_BATTLEGROUND (13). As Logger has higher LogLevel msg is not sent to any appender * sLog->outError(LOG_FILTER_BATTLEGROUND, "Some error msg related to Battelgrounds") - Msg is sent to Logger root (Type 0) as no Logger was found with Type LOG_FILTER_BATTLEGROUND (13). Msg has lower LogLevel and is sent to Appender Console - Appender Console has lower LogLevel: Msg is logged to Console --- src/server/shared/Logging/AppenderFile.cpp | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/server/shared/Logging/AppenderFile.cpp (limited to 'src/server/shared/Logging/AppenderFile.cpp') diff --git a/src/server/shared/Logging/AppenderFile.cpp b/src/server/shared/Logging/AppenderFile.cpp new file mode 100644 index 00000000000..30c1f271c96 --- /dev/null +++ b/src/server/shared/Logging/AppenderFile.cpp @@ -0,0 +1,54 @@ +#include "AppenderFile.h" +#include "Common.h" + +AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, const char* _filename, const char* _mode, bool _backup) + : Appender(id, name, APPENDER_FILE, level) + , filename(_filename) + , mode(_mode) + , backup(_backup) +{ + dynamicName = std::string::npos != filename.find("%u"); + if (!dynamicName) + logfile = OpenFile(_filename, _mode, _backup); +} + +AppenderFile::~AppenderFile() +{ + if (logfile) + { + fclose(logfile); + logfile = NULL; + } +} + +void AppenderFile::_write(LogMessage& message) +{ + if (dynamicName) + { + char namebuf[TRINITY_PATH_MAX]; + snprintf(namebuf, TRINITY_PATH_MAX, filename.c_str(), message.param1); + logfile = OpenFile(namebuf, mode, backup); + } + + if (logfile) + { + fprintf(logfile, "%s %-5s [%-15s] %s", message.getTimeStr().c_str(), Appender::getLogLevelString(message.level), Appender::getLogFilterTypeString(message.type), message.text.c_str()); + + fflush(logfile); + + if (dynamicName) + fclose(logfile); + } +} + +FILE* AppenderFile::OpenFile(std::string const &filename, std::string const &mode, bool backup) +{ + if (mode == "w" && backup) + { + std::string newName(filename); + newName.push_back('.'); + newName.append(LogMessage::getTimeStr(time(NULL))); + rename(filename.c_str(), newName.c_str()); // no error handling... if we couldn't make a backup, just ignore + } + return fopen(filename.c_str(), mode.c_str()); +} -- cgit v1.2.3 From 10891028279762eb14688ec07bc22dffe3b26886 Mon Sep 17 00:00:00 2001 From: Spp Date: Fri, 3 Aug 2012 17:29:43 +0200 Subject: Add missing Copyright headers and some clarification to config files... ¬¬ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/authserver/authserver.conf.dist | 161 ++++++------ src/server/shared/Logging/Appender.cpp | 17 ++ src/server/shared/Logging/Appender.h | 17 ++ src/server/shared/Logging/AppenderConsole.cpp | 17 ++ src/server/shared/Logging/AppenderConsole.h | 17 ++ src/server/shared/Logging/AppenderDB.cpp | 17 ++ src/server/shared/Logging/AppenderDB.h | 17 ++ src/server/shared/Logging/AppenderFile.cpp | 17 ++ src/server/shared/Logging/AppenderFile.h | 17 ++ src/server/shared/Logging/LogOperation.cpp | 17 ++ src/server/shared/Logging/LogOperation.h | 17 ++ src/server/shared/Logging/LogWorker.cpp | 17 ++ src/server/shared/Logging/LogWorker.h | 17 ++ src/server/shared/Logging/Logger.cpp | 17 ++ src/server/shared/Logging/Logger.h | 17 ++ src/server/worldserver/worldserver.conf.dist | 347 +++++++++++++------------- 16 files changed, 497 insertions(+), 249 deletions(-) (limited to 'src/server/shared/Logging/AppenderFile.cpp') diff --git a/src/server/authserver/authserver.conf.dist b/src/server/authserver/authserver.conf.dist index 875d952b14c..93bbc9e3872 100644 --- a/src/server/authserver/authserver.conf.dist +++ b/src/server/authserver/authserver.conf.dist @@ -68,6 +68,89 @@ BindIP = "0.0.0.0" PidFile = "" +# +# UseProcessors +# Description: Processors mask for Windows based multi-processor systems. +# Default: 0 - (Selected by OS) +# 1+ - (Bit mask value of selected processors) + +UseProcessors = 0 + +# +# ProcessPriority +# Description: Process priority setting for Windows based systems. +# Default: 1 - (High) +# 0 - (Normal) + +ProcessPriority = 1 + +# +# RealmsStateUpdateDelay +# Description: Time (in seconds) between realm list updates. +# Default: 20 - (Enabled) +# 0 - (Disabled) + +RealmsStateUpdateDelay = 20 + +# +# WrongPass.MaxCount +# Description: Number of login attemps with wrong password before the account or IP will be +# banned. +# Default: 0 - (Disabled) +# 1+ - (Enabled) + +WrongPass.MaxCount = 0 + +# +# WrongPass.BanTime +# Description: Time (in seconds) for banning account or IP for invalid login attempts. +# Default: 600 - (10 minutes) +# 0 - (Permanent ban) + +WrongPass.BanTime = 600 + +# +# WrongPass.BanType +# Description: Ban type for invalid login attempts. +# Default: 0 - (Ban IP) +# 1 - (Ban Account) + +WrongPass.BanType = 0 + +# +################################################################################################### + +################################################################################################### +# MYSQL SETTINGS +# +# LoginDatabaseInfo +# Description: Database connection settings for the realm server. +# Example: "hostname;port;username;password;database" +# ".;somenumber;username;password;database" - (Use named pipes on Windows +# "enable-named-pipe" to [mysqld] +# section my.ini) +# ".;/path/to/unix_socket;username;password;database" - (use Unix sockets on +# Unix/Linux) +# Default: "127.0.0.1;3306;trinity;trinity;auth" + +LoginDatabaseInfo = "127.0.0.1;3306;trinity;trinity;auth" + +# +# LoginDatabase.WorkerThreads +# Description: The amount of worker threads spawned to handle asynchronous (delayed) MySQL +# statements. Each worker thread is mirrored with its own connection to the +# Default: 1 + +LoginDatabase.WorkerThreads = 1 + +# +################################################################################################### + +################################################################################################### +# +# Logging system options. +# Note: As it uses dynamic option naming, all options related to one appender or logger are grouped. +# # # Appender config values: Given a appender "name" the following options # can be read: @@ -187,81 +270,3 @@ Appender.Auth.Mode=w Logger.root.Type=0 Logger.root.Level=3 Logger.root.Appenders=Console Auth - -# -# UseProcessors -# Description: Processors mask for Windows based multi-processor systems. -# Default: 0 - (Selected by OS) -# 1+ - (Bit mask value of selected processors) - -UseProcessors = 0 - -# -# ProcessPriority -# Description: Process priority setting for Windows based systems. -# Default: 1 - (High) -# 0 - (Normal) - -ProcessPriority = 1 - -# -# RealmsStateUpdateDelay -# Description: Time (in seconds) between realm list updates. -# Default: 20 - (Enabled) -# 0 - (Disabled) - -RealmsStateUpdateDelay = 20 - -# -# WrongPass.MaxCount -# Description: Number of login attemps with wrong password before the account or IP will be -# banned. -# Default: 0 - (Disabled) -# 1+ - (Enabled) - -WrongPass.MaxCount = 0 - -# -# WrongPass.BanTime -# Description: Time (in seconds) for banning account or IP for invalid login attempts. -# Default: 600 - (10 minutes) -# 0 - (Permanent ban) - -WrongPass.BanTime = 600 - -# -# WrongPass.BanType -# Description: Ban type for invalid login attempts. -# Default: 0 - (Ban IP) -# 1 - (Ban Account) - -WrongPass.BanType = 0 - -# -################################################################################################### - -################################################################################################### -# MYSQL SETTINGS -# -# LoginDatabaseInfo -# Description: Database connection settings for the realm server. -# Example: "hostname;port;username;password;database" -# ".;somenumber;username;password;database" - (Use named pipes on Windows -# "enable-named-pipe" to [mysqld] -# section my.ini) -# ".;/path/to/unix_socket;username;password;database" - (use Unix sockets on -# Unix/Linux) -# Default: "127.0.0.1;3306;trinity;trinity;auth" - -LoginDatabaseInfo = "127.0.0.1;3306;trinity;trinity;auth" - -# -# LoginDatabase.WorkerThreads -# Description: The amount of worker threads spawned to handle asynchronous (delayed) MySQL -# statements. Each worker thread is mirrored with its own connection to the -# Default: 1 - -LoginDatabase.WorkerThreads = 1 - -# -################################################################################################### diff --git a/src/server/shared/Logging/Appender.cpp b/src/server/shared/Logging/Appender.cpp index 38d58f1ffb5..0b92e74c1e9 100644 --- a/src/server/shared/Logging/Appender.cpp +++ b/src/server/shared/Logging/Appender.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #include "Appender.h" #include "Common.h" diff --git a/src/server/shared/Logging/Appender.h b/src/server/shared/Logging/Appender.h index c32f51e5a88..3105f0e6bb4 100644 --- a/src/server/shared/Logging/Appender.h +++ b/src/server/shared/Logging/Appender.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #ifndef APPENDER_H #define APPENDER_H diff --git a/src/server/shared/Logging/AppenderConsole.cpp b/src/server/shared/Logging/AppenderConsole.cpp index ad81a883bfa..30c7cc4d135 100644 --- a/src/server/shared/Logging/AppenderConsole.cpp +++ b/src/server/shared/Logging/AppenderConsole.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #include "AppenderConsole.h" #include "Config.h" #include "Util.h" diff --git a/src/server/shared/Logging/AppenderConsole.h b/src/server/shared/Logging/AppenderConsole.h index a9f46cf9c4a..b81fe6dde57 100644 --- a/src/server/shared/Logging/AppenderConsole.h +++ b/src/server/shared/Logging/AppenderConsole.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #ifndef APPENDERCONSOLE_H #define APPENDERCONSOLE_H diff --git a/src/server/shared/Logging/AppenderDB.cpp b/src/server/shared/Logging/AppenderDB.cpp index 6f3737adf4d..63af9176193 100644 --- a/src/server/shared/Logging/AppenderDB.cpp +++ b/src/server/shared/Logging/AppenderDB.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #include "AppenderDB.h" /* FIXME diff --git a/src/server/shared/Logging/AppenderDB.h b/src/server/shared/Logging/AppenderDB.h index ca15fc1a1d5..4399195b181 100644 --- a/src/server/shared/Logging/AppenderDB.h +++ b/src/server/shared/Logging/AppenderDB.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #ifndef APPENDERDB_H #define APPENDERDB_H diff --git a/src/server/shared/Logging/AppenderFile.cpp b/src/server/shared/Logging/AppenderFile.cpp index 30c1f271c96..93c02913aeb 100644 --- a/src/server/shared/Logging/AppenderFile.cpp +++ b/src/server/shared/Logging/AppenderFile.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #include "AppenderFile.h" #include "Common.h" diff --git a/src/server/shared/Logging/AppenderFile.h b/src/server/shared/Logging/AppenderFile.h index a01ea947334..bbc500f9e76 100644 --- a/src/server/shared/Logging/AppenderFile.h +++ b/src/server/shared/Logging/AppenderFile.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #ifndef APPENDERFILE_H #define APPENDERFILE_H diff --git a/src/server/shared/Logging/LogOperation.cpp b/src/server/shared/Logging/LogOperation.cpp index 59368e519cd..b36dd3a8b1e 100644 --- a/src/server/shared/Logging/LogOperation.cpp +++ b/src/server/shared/Logging/LogOperation.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #include "LogOperation.h" #include "Logger.h" diff --git a/src/server/shared/Logging/LogOperation.h b/src/server/shared/Logging/LogOperation.h index 046ff44e62e..d872670d756 100644 --- a/src/server/shared/Logging/LogOperation.h +++ b/src/server/shared/Logging/LogOperation.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #ifndef LOGOPERATION_H #define LOGOPERATION_H diff --git a/src/server/shared/Logging/LogWorker.cpp b/src/server/shared/Logging/LogWorker.cpp index 4dc71f7f878..a12faaf224c 100644 --- a/src/server/shared/Logging/LogWorker.cpp +++ b/src/server/shared/Logging/LogWorker.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #include "LogWorker.h" LogWorker::LogWorker() diff --git a/src/server/shared/Logging/LogWorker.h b/src/server/shared/Logging/LogWorker.h index fe51be5376c..ea1744f9790 100644 --- a/src/server/shared/Logging/LogWorker.h +++ b/src/server/shared/Logging/LogWorker.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #ifndef LOGWORKER_H #define LOGWORKER_H diff --git a/src/server/shared/Logging/Logger.cpp b/src/server/shared/Logging/Logger.cpp index 7464012c0ac..10276eb3acb 100644 --- a/src/server/shared/Logging/Logger.cpp +++ b/src/server/shared/Logging/Logger.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #include "Logger.h" Logger::Logger(): name(""), type(LOG_FILTER_GENERAL), level(LOG_LEVEL_DISABLED) diff --git a/src/server/shared/Logging/Logger.h b/src/server/shared/Logging/Logger.h index 10b3991a537..9d13f08620f 100644 --- a/src/server/shared/Logging/Logger.h +++ b/src/server/shared/Logging/Logger.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + #ifndef LOGGER_H #define LOGGER_H diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist index 01dbd5eaf2d..99cb415dc98 100644 --- a/src/server/worldserver/worldserver.conf.dist +++ b/src/server/worldserver/worldserver.conf.dist @@ -403,177 +403,6 @@ PersistentCharacterCleanFlags = 0 PidFile = "" -# -# Appender config values: Given a appender "name" the following options -# can be read: -# -# Appender.name.Type -# Description: Type of appender. Extra appender config options -# will be read depending on this value -# Default: 0 - (None) -# 1 - (Console) -# 2 - (File) -# 3 - (DB) -# -# Appender.name.Level -# Description: Appender level of logging -# Default: 0 - (Disabled) -# 1 - (Trace) -# 2 - (Debug) -# 3 - (Info) -# 4 - (Warn) -# 5 - (Error) -# 6 - (Fatal) -# -# Appender.name.Colors -# Description: Colors for log messages -# (Format: "fatal error warn info debug trace"). -# (Only used with Type = 1) -# Default: "" - no colors -# Colors: 0 - BLACK -# 1 - RED -# 2 - GREEN -# 3 - BROWN -# 4 - BLUE -# 5 - MAGENTA -# 6 - CYAN -# 7 - GREY -# 8 - YELLOW -# 9 - LRED -# 10 - LGREEN -# 11 - LBLUE -# 12 - LMAGENTA -# 13 - LCYAN -# 14 - WHITE -# Example: "13 11 9 5 3 1" -# -# Appender.name.File -# Description: Name of the file -# Allows to use one "%u" to create dynamic files -# (Only used with Type = 2) -# -# Appender.name.Mode -# Description: Mode to open the file -# (Only used with Type = 2) -# Default: a - (Append) -# w - (Overwrite) -# -# Appender.name.Backup -# Description: Make a backup of existing file before overwrite -# (Only used with Mode = w) -# Default: 0 - false -# 1 - true -# -# Appender.name.Timestamp -# Description: Append timestamp to the log file name. -# Logname_YYYY-MM-DD_HH-MM-SS.Ext for Logname.Ext -# (Only used with Type = 2) -# -# Logger config values: Given a logger "name" the following options -# can be read: -# -# Logger.name.Type -# Description: Type of logger. Logs anything related to... -# If no logger with type = 0 exists core will create -# it but disabled. Logger with type = 0 is the -# default one, used when there is no other specific -# logger configured for other logger types -# Default: 0 - Default. Each type that has no config will -# rely on this one. Core will create this logger -# (disabled) if it's not configured -# 1 - Units that doesn't fit in other categories -# 2 - Pets -# 3 - Vehicles -# 4 - C++ AI, instance scripts, etc. -# 5 - DB AI, such as SAI, EAI, CreatureAI -# 6 - DB map scripts -# 7 - Network input/output, -# such as packet handlers and netcode logs -# 8 - Spellsystem and aurasystem -# 9 - Achievement system -# 10 - Condition system -# 11 - Pool system -# 12 - Auction house -# 13 - Arena's and battlegrounds -# 14 - Outdoor PVP -# 15 - Chat system -# 16 - LFG system -# 17 - Maps, instances (not scripts), -# grids, cells, visibility, etc. -# 18 - Player that doesn't fit in other categories. -# 19 - Player loading from DB -# (Player::_LoadXXX functions) -# 20 - Items -# 21 - Player skills (do not confuse with spells) -# 22 - Player chat logs -# 23 - loot -# 24 - guilds -# 25 - transports -# 26 - SQL. DB errors and SQL Driver -# 27 - GM Commands -# 28 - Remote Access Commands -# 29 - Warden -# 30 - Authserver -# 31 - Worldserver -# 32 - Game Events -# 33 - Calendar -# -# Logger.name.Level -# Description: Logger level of logging -# Default: 0 - (Disabled) -# 1 - (Trace) -# 2 - (Debug) -# 3 - (Info) -# 4 - (Warn) -# 5 - (Error) -# 6 - (Fatal) -# -# Logger.name.Appenders -# Description: List of appenders linked to logger -# (Using spaces as separator). - -# -# Appenders -# Description: List of Appenders to read from config -# (Using spaces as separator). -# Default: "Console Server" -# -# Loggers -# Description: List of Loggers to read from config -# (Using spaces as separator). -# Default: "root" - -Loggers=root GM SQL -Appenders=Console Server GM SQL - -Appender.Console.Type=1 -Appender.Console.Level=2 - -Appender.Server.Type=2 -Appender.Server.Level=2 -Appender.Server.File=Server.log -Appender.Server.Mode=w - -Appender.GM.Type=2 -Appender.GM.Level=2 -Appender.GM.File=gm_#%u.log - -Appender.SQL.Type=2 -Appender.SQL.Level=2 -Appender.SQL.File=SQL.log - -Logger.root.Type=0 -Logger.root.Level=3 -Logger.root.Appenders=Console Server - -Logger.SQL.Type=26 -Logger.SQL.Level=3 -Logger.SQL.Appenders=Console Server SQL - -Logger.GM.Type=27 -Logger.GM.Level=3 -Logger.GM.Appenders=Console Server GM - # # ChatLogs.Channel # Description: Log custom channel chat. @@ -648,6 +477,7 @@ ChatLogs.Addon = 0 ChatLogs.BattleGround = 0 +# Extended Logging system configuration moved to end of file (on purpose) # ################################################################################################### @@ -2746,3 +2576,178 @@ PlayerDump.DisallowOverwrite = 1 # ################################################################################################### + +################################################################################################### +# +# Logging system options. +# Note: As it uses dynamic option naming, all options related to one appender or logger are grouped. +# +# +# Appender config values: Given a appender "name" the following options +# can be read: +# +# Appender.name.Type +# Description: Type of appender. Extra appender config options +# will be read depending on this value +# Default: 0 - (None) +# 1 - (Console) +# 2 - (File) +# 3 - (DB) +# +# Appender.name.Level +# Description: Appender level of logging +# Default: 0 - (Disabled) +# 1 - (Trace) +# 2 - (Debug) +# 3 - (Info) +# 4 - (Warn) +# 5 - (Error) +# 6 - (Fatal) +# +# Appender.name.Colors +# Description: Colors for log messages +# (Format: "fatal error warn info debug trace"). +# (Only used with Type = 1) +# Default: "" - no colors +# Colors: 0 - BLACK +# 1 - RED +# 2 - GREEN +# 3 - BROWN +# 4 - BLUE +# 5 - MAGENTA +# 6 - CYAN +# 7 - GREY +# 8 - YELLOW +# 9 - LRED +# 10 - LGREEN +# 11 - LBLUE +# 12 - LMAGENTA +# 13 - LCYAN +# 14 - WHITE +# Example: "13 11 9 5 3 1" +# +# Appender.name.File +# Description: Name of the file +# Allows to use one "%u" to create dynamic files +# (Only used with Type = 2) +# +# Appender.name.Mode +# Description: Mode to open the file +# (Only used with Type = 2) +# Default: a - (Append) +# w - (Overwrite) +# +# Appender.name.Backup +# Description: Make a backup of existing file before overwrite +# (Only used with Mode = w) +# Default: 0 - false +# 1 - true +# +# Appender.name.Timestamp +# Description: Append timestamp to the log file name. +# Logname_YYYY-MM-DD_HH-MM-SS.Ext for Logname.Ext +# (Only used with Type = 2) +# +# Logger config values: Given a logger "name" the following options +# can be read: +# +# Logger.name.Type +# Description: Type of logger. Logs anything related to... +# If no logger with type = 0 exists core will create +# it but disabled. Logger with type = 0 is the +# default one, used when there is no other specific +# logger configured for other logger types +# Default: 0 - Default. Each type that has no config will +# rely on this one. Core will create this logger +# (disabled) if it's not configured +# 1 - Units that doesn't fit in other categories +# 2 - Pets +# 3 - Vehicles +# 4 - C++ AI, instance scripts, etc. +# 5 - DB AI, such as SAI, EAI, CreatureAI +# 6 - DB map scripts +# 7 - Network input/output, +# such as packet handlers and netcode logs +# 8 - Spellsystem and aurasystem +# 9 - Achievement system +# 10 - Condition system +# 11 - Pool system +# 12 - Auction house +# 13 - Arena's and battlegrounds +# 14 - Outdoor PVP +# 15 - Chat system +# 16 - LFG system +# 17 - Maps, instances (not scripts), +# grids, cells, visibility, etc. +# 18 - Player that doesn't fit in other categories. +# 19 - Player loading from DB +# (Player::_LoadXXX functions) +# 20 - Items +# 21 - Player skills (do not confuse with spells) +# 22 - Player chat logs +# 23 - loot +# 24 - guilds +# 25 - transports +# 26 - SQL. DB errors and SQL Driver +# 27 - GM Commands +# 28 - Remote Access Commands +# 29 - Warden +# 30 - Authserver +# 31 - Worldserver +# 32 - Game Events +# 33 - Calendar +# +# Logger.name.Level +# Description: Logger level of logging +# Default: 0 - (Disabled) +# 1 - (Trace) +# 2 - (Debug) +# 3 - (Info) +# 4 - (Warn) +# 5 - (Error) +# 6 - (Fatal) +# +# Logger.name.Appenders +# Description: List of appenders linked to logger +# (Using spaces as separator). +# +# Appenders +# Description: List of Appenders to read from config +# (Using spaces as separator). +# Default: "Console Server" +# +# Loggers +# Description: List of Loggers to read from config +# (Using spaces as separator). +# Default: "root" + +Loggers=root GM SQL +Appenders=Console Server GM SQL + +Appender.Console.Type=1 +Appender.Console.Level=2 + +Appender.Server.Type=2 +Appender.Server.Level=2 +Appender.Server.File=Server.log +Appender.Server.Mode=w + +Appender.GM.Type=2 +Appender.GM.Level=2 +Appender.GM.File=gm_#%u.log + +Appender.SQL.Type=2 +Appender.SQL.Level=2 +Appender.SQL.File=SQL.log + +Logger.root.Type=0 +Logger.root.Level=3 +Logger.root.Appenders=Console Server + +Logger.SQL.Type=26 +Logger.SQL.Level=3 +Logger.SQL.Appenders=Console Server SQL + +Logger.GM.Type=27 +Logger.GM.Level=3 +Logger.GM.Appenders=Console Server GM -- cgit v1.2.3 From af92a36e889d5fc1a7575300e7652d111ccf87d9 Mon Sep 17 00:00:00 2001 From: joschiwald Date: Sat, 4 Aug 2012 02:55:11 +0100 Subject: Core/Logging: Use config LogsDir to save log files (re-added) --- src/server/shared/Logging/AppenderFile.cpp | 5 +++-- src/server/shared/Logging/AppenderFile.h | 3 ++- src/server/shared/Logging/Log.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/server/shared/Logging/AppenderFile.cpp') diff --git a/src/server/shared/Logging/AppenderFile.cpp b/src/server/shared/Logging/AppenderFile.cpp index 93c02913aeb..cb875240c46 100644 --- a/src/server/shared/Logging/AppenderFile.cpp +++ b/src/server/shared/Logging/AppenderFile.cpp @@ -18,9 +18,10 @@ #include "AppenderFile.h" #include "Common.h" -AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, const char* _filename, const char* _mode, bool _backup) +AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, const char* _filename, const char* _logDir, const char* _mode, bool _backup) : Appender(id, name, APPENDER_FILE, level) , filename(_filename) + , logDir(_logDir) , mode(_mode) , backup(_backup) { @@ -67,5 +68,5 @@ FILE* AppenderFile::OpenFile(std::string const &filename, std::string const &mod newName.append(LogMessage::getTimeStr(time(NULL))); rename(filename.c_str(), newName.c_str()); // no error handling... if we couldn't make a backup, just ignore } - return fopen(filename.c_str(), mode.c_str()); + return fopen((logDir + filename).c_str(), mode.c_str()); } diff --git a/src/server/shared/Logging/AppenderFile.h b/src/server/shared/Logging/AppenderFile.h index bbc500f9e76..8d8b0c43a54 100644 --- a/src/server/shared/Logging/AppenderFile.h +++ b/src/server/shared/Logging/AppenderFile.h @@ -23,7 +23,7 @@ class AppenderFile: public Appender { public: - AppenderFile(uint8 _id, std::string const& _name, LogLevel level, const char* filename, const char* mode, bool backup); + AppenderFile(uint8 _id, std::string const& _name, LogLevel level, const char* filename, const char* logDir, const char* mode, bool backup); ~AppenderFile(); FILE* OpenFile(std::string const& _name, std::string const& _mode, bool _backup); @@ -31,6 +31,7 @@ class AppenderFile: public Appender void _write(LogMessage& message); FILE* logfile; std::string filename; + std::string logDir; std::string mode; bool dynamicName; bool backup; diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp index 17c6df44125..2ced38847be 100755 --- a/src/server/shared/Logging/Log.cpp +++ b/src/server/shared/Logging/Log.cpp @@ -127,7 +127,7 @@ void Log::CreateAppenderFromConfig(const char* name) } uint8 id = NextAppenderId(); - appenders[id] = new AppenderFile(id, name, level, filename.c_str(), mode.c_str(), backup); + appenders[id] = new AppenderFile(id, name, level, filename.c_str(), m_logsDir.c_str(), mode.c_str(), backup); //fprintf(stdout, "Log::CreateAppenderFromConfig: Created Appender %s (%u), Type FILE, Mask %u, File %s, Mode %s\n", name, id, level, filename.c_str(), mode.c_str()); // DEBUG - RemoveMe break; } -- cgit v1.2.3 From 3f42094b9c563d2b2d5f2dfe43d8d47c9114f71f Mon Sep 17 00:00:00 2001 From: Spp Date: Sun, 5 Aug 2012 15:38:25 +0200 Subject: Core/Logging: Add option to remove timestamp, Log Level and Log Filter Type from logged msgs - Appender config option .Timestamp and .Backup became obsolete - New Appender config option .Flags added Appender Console prefixes Log Level and Log Filter Type to the logged text as default Appender File prefixes Timestamp, Log Level and Log Filter Type to the logged text as default --- src/server/authserver/authserver.conf.dist | 19 +++++------ src/server/game/Handlers/CharacterHandler.cpp | 2 +- src/server/game/Server/WorldSession.cpp | 2 +- src/server/shared/Logging/Appender.cpp | 48 ++++++++++++++++++++++++--- src/server/shared/Logging/Appender.h | 21 ++++++++++-- src/server/shared/Logging/AppenderConsole.cpp | 10 +++--- src/server/shared/Logging/AppenderConsole.h | 2 +- src/server/shared/Logging/AppenderFile.cpp | 11 +++--- src/server/shared/Logging/AppenderFile.h | 2 +- src/server/shared/Logging/Log.cpp | 11 +++--- src/server/worldserver/worldserver.conf.dist | 19 +++++------ 11 files changed, 100 insertions(+), 47 deletions(-) (limited to 'src/server/shared/Logging/AppenderFile.cpp') diff --git a/src/server/authserver/authserver.conf.dist b/src/server/authserver/authserver.conf.dist index d77b40e6591..30a319237a6 100644 --- a/src/server/authserver/authserver.conf.dist +++ b/src/server/authserver/authserver.conf.dist @@ -206,16 +206,15 @@ LoginDatabase.WorkerThreads = 1 # Default: a - (Append) # w - (Overwrite) # -# Appender.name.Backup -# Description: Make a backup of existing file before overwrite -# (Only used with Mode = w) -# Default: 0 - false -# 1 - true -# -# Appender.name.Timestamp -# Description: Append timestamp to the log file name. -# Logname_YYYY-MM-DD_HH-MM-SS.Ext for Logname.Ext -# (Only used with Type = 2) +# Appender.name.Flags +# Description: +# Default: Console = 6, File = 7, DB = 0 +# 0 - None +# 1 - Prefix Timestamp to the text +# 2 - Prefix Log Level to the text +# 4 - Prefix Log Filter type to the text +# 8 - Append timestamp to the log file name. Format: YYYY-MM-DD_HH-MM-SS (Only used with Type = 2) +# 16 - Make a backup of existing file before overwrite (Only used with Mode = w) # # Logger config values: Given a logger "name" the following options # can be read: diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index df515f879f8..9aecf3c4c25 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -1006,7 +1006,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder) SendNotification(LANG_GM_ON); std::string IP_str = GetRemoteAddress(); - sLog->outDebug(LOG_FILTER_PLAYER, "Account: %d (IP: %s) Login Character:[%s] (GUID: %u) Level: %d", + sLog->outInfo(LOG_FILTER_PLAYER_LOADING, "Account: %d (IP: %s) Login Character:[%s] (GUID: %u) Level: %d", GetAccountId(), IP_str.c_str(), pCurrChar->GetName(), pCurrChar->GetGUIDLow(), pCurrChar->getLevel()); if (!pCurrChar->IsStandState() && !pCurrChar->HasUnitState(UNIT_STATE_STUNNED)) diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 6e45ebf37c1..6fdbf8a5358 100755 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -534,7 +534,7 @@ void WorldSession::LogoutPlayer(bool Save) // e.g if he got disconnected during a transfer to another map // calls to GetMap in this case may cause crashes _player->CleanupsBeforeDelete(); - sLog->outDebug(LOG_FILTER_PLAYER, "Account: %d (IP: %s) Logout Character:[%s] (GUID: %u) Level: %d", GetAccountId(), GetRemoteAddress().c_str(), _player->GetName(), _player->GetGUIDLow(), _player->getLevel()); + sLog->outInfo(LOG_FILTER_PLAYER_LOADING, "Account: %d (IP: %s) Logout Character:[%s] (GUID: %u) Level: %d", GetAccountId(), GetRemoteAddress().c_str(), _player->GetName(), _player->GetGUIDLow(), _player->getLevel()); if (Map* _map = _player->FindMap()) _map->RemovePlayerFromMap(_player, true); diff --git a/src/server/shared/Logging/Appender.cpp b/src/server/shared/Logging/Appender.cpp index 0b92e74c1e9..db7857064df 100644 --- a/src/server/shared/Logging/Appender.cpp +++ b/src/server/shared/Logging/Appender.cpp @@ -31,8 +31,8 @@ std::string LogMessage::getTimeStr() return getTimeStr(mtime); } -Appender::Appender(uint8 _id, std::string const& _name, AppenderType _type /* = APPENDER_NONE*/, LogLevel _level /* = LOG_LEVEL_DISABLED */): -id(_id), name(_name), type(_type), level(_level) +Appender::Appender(uint8 _id, std::string const& _name, AppenderType _type /* = APPENDER_NONE*/, LogLevel _level /* = LOG_LEVEL_DISABLED */, AppenderFlags _flags /* = APPENDER_FLAGS_NONE */): +id(_id), name(_name), type(_type), level(_level), flags(_flags) { } @@ -60,6 +60,11 @@ LogLevel Appender::getLogLevel() const return level; } +AppenderFlags Appender::getFlags() const +{ + return flags; +} + void Appender::setLogLevel(LogLevel _level) { level = _level; @@ -67,9 +72,40 @@ void Appender::setLogLevel(LogLevel _level) void Appender::write(LogMessage& message) { - if (level && level <= message.level) - _write(message); - //else fprintf(stderr, "Appender::write: Appender %s, Level %s. Msg %s Level %s Type %s WRONG LEVEL MASK\n", getName().c_str(), getLogLevelString(level), message.text.c_str(), getLogLevelString(message.level), getLogFilterTypeString(message.type)); // DEBUG - RemoveMe + if (!level || level > message.level) + { + //fprintf(stderr, "Appender::write: Appender %s, Level %s. Msg %s Level %s Type %s WRONG LEVEL MASK\n", getName().c_str(), getLogLevelString(level), message.text.c_str(), getLogLevelString(message.level), getLogFilterTypeString(message.type)); // DEBUG - RemoveMe + return; + } + + message.prefix.clear(); + if (flags & APPENDER_FLAGS_PREFIX_TIMESTAMP) + message.prefix.append(message.getTimeStr().c_str()); + + if (flags & APPENDER_FLAGS_PREFIX_LOGLEVEL) + { + if (!message.prefix.empty()) + message.prefix.push_back(' '); + + char text[MAX_QUERY_LEN]; + snprintf(text, MAX_QUERY_LEN, "%-5s", Appender::getLogLevelString(message.level)); + message.prefix.append(text); + } + + if (flags & APPENDER_FLAGS_PREFIX_LOGFILTERTYPE) + { + if (!message.prefix.empty()) + message.prefix.push_back(' '); + + char text[MAX_QUERY_LEN]; + snprintf(text, MAX_QUERY_LEN, "[%-15s]", Appender::getLogFilterTypeString(message.type)); + message.prefix.append(text); + } + + if (!message.prefix.empty()) + message.prefix.push_back(' '); + + _write(message); } const char* Appender::getLogLevelString(LogLevel level) @@ -163,6 +199,8 @@ char const* Appender::getLogFilterTypeString(LogFilterType type) return "WORLDSERVER"; case LOG_FILTER_GAMEEVENTS: return "GAMEEVENTS"; + case LOG_FILTER_CALENDAR: + return "CALENDAR"; default: break; } diff --git a/src/server/shared/Logging/Appender.h b/src/server/shared/Logging/Appender.h index 3105f0e6bb4..429a685d4ee 100644 --- a/src/server/shared/Logging/Appender.h +++ b/src/server/shared/Logging/Appender.h @@ -85,9 +85,23 @@ enum AppenderType APPENDER_DB, }; +enum AppenderFlags +{ + APPENDER_FLAGS_NONE = 0x00, + APPENDER_FLAGS_PREFIX_TIMESTAMP = 0x01, + APPENDER_FLAGS_PREFIX_LOGLEVEL = 0x02, + APPENDER_FLAGS_PREFIX_LOGFILTERTYPE = 0x04, + APPENDER_FLAGS_USE_TIMESTAMP = 0x08, // only used by FileAppender + APPENDER_FLAGS_MAKE_FILE_BACKUP = 0x10 // only used by FileAppender +}; + struct LogMessage { - LogMessage(LogLevel _level, LogFilterType _type, std::string _text): level(_level), type(_type), text(_text) + LogMessage(LogLevel _level, LogFilterType _type, std::string _text) + : level(_level) + , type(_type) + , text(_text) + , param1(0) { mtime = time(NULL); } @@ -98,6 +112,7 @@ struct LogMessage LogLevel level; LogFilterType type; std::string text; + std::string prefix; uint32 param1; time_t mtime; }; @@ -105,13 +120,14 @@ struct LogMessage class Appender { public: - Appender(uint8 _id, std::string const& name, AppenderType type = APPENDER_NONE, LogLevel level = LOG_LEVEL_DISABLED); + Appender(uint8 _id, std::string const& name, AppenderType type = APPENDER_NONE, LogLevel level = LOG_LEVEL_DISABLED, AppenderFlags flags = APPENDER_FLAGS_NONE); virtual ~Appender(); uint8 getId() const; std::string const& getName() const; AppenderType getType() const; LogLevel getLogLevel() const; + AppenderFlags getFlags() const; void setLogLevel(LogLevel); void write(LogMessage& message); @@ -125,6 +141,7 @@ class Appender std::string name; AppenderType type; LogLevel level; + AppenderFlags flags; }; typedef std::map AppenderMap; diff --git a/src/server/shared/Logging/AppenderConsole.cpp b/src/server/shared/Logging/AppenderConsole.cpp index 30c7cc4d135..839f8512ad7 100644 --- a/src/server/shared/Logging/AppenderConsole.cpp +++ b/src/server/shared/Logging/AppenderConsole.cpp @@ -21,9 +21,11 @@ #include -AppenderConsole::AppenderConsole(uint8 id, std::string const& name, LogLevel level): -Appender(id, name, APPENDER_CONSOLE, level), _colored(false), _colors() +AppenderConsole::AppenderConsole(uint8 id, std::string const& name, LogLevel level, AppenderFlags flags): +Appender(id, name, APPENDER_CONSOLE, level, flags), _colored(false) { + for (uint8 i = 0; i < MaxLogLevels; ++i) + _colors[i] = ColorTypes(MaxColors); } void AppenderConsole::InitColors(std::string const& str) @@ -183,9 +185,9 @@ void AppenderConsole::_write(LogMessage& message) } SetColor(stdout_stream, _colors[index]); - utf8printf(stdout_stream ? stdout : stderr, "%s %-5s [%-15s] %s", message.getTimeStr().c_str(), Appender::getLogLevelString(message.level), Appender::getLogFilterTypeString(message.type), message.text.c_str()); + utf8printf(stdout_stream ? stdout : stderr, "%s%s", message.prefix.c_str(), message.text.c_str()); ResetColor(stdout_stream); } else - utf8printf(stdout_stream ? stdout : stderr, "%s %-5s [%-15s] %s", message.getTimeStr().c_str(), Appender::getLogLevelString(message.level), Appender::getLogFilterTypeString(message.type), message.text.c_str()); + utf8printf(stdout_stream ? stdout : stderr, "%s%s", message.prefix.c_str(), message.text.c_str()); } diff --git a/src/server/shared/Logging/AppenderConsole.h b/src/server/shared/Logging/AppenderConsole.h index b81fe6dde57..ad7d9543cdb 100644 --- a/src/server/shared/Logging/AppenderConsole.h +++ b/src/server/shared/Logging/AppenderConsole.h @@ -45,7 +45,7 @@ const uint8 MaxColors = uint8(WHITE) + 1; class AppenderConsole: public Appender { public: - AppenderConsole(uint8 _id, std::string const& name, LogLevel level); + AppenderConsole(uint8 _id, std::string const& name, LogLevel level, AppenderFlags flags); void InitColors(const std::string& init_str); private: diff --git a/src/server/shared/Logging/AppenderFile.cpp b/src/server/shared/Logging/AppenderFile.cpp index cb875240c46..d66771b9055 100644 --- a/src/server/shared/Logging/AppenderFile.cpp +++ b/src/server/shared/Logging/AppenderFile.cpp @@ -18,16 +18,16 @@ #include "AppenderFile.h" #include "Common.h" -AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, const char* _filename, const char* _logDir, const char* _mode, bool _backup) - : Appender(id, name, APPENDER_FILE, level) +AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, const char* _filename, const char* _logDir, const char* _mode, AppenderFlags _flags) + : Appender(id, name, APPENDER_FILE, level, _flags) , filename(_filename) , logDir(_logDir) , mode(_mode) - , backup(_backup) { dynamicName = std::string::npos != filename.find("%u"); + backup = _flags & APPENDER_FLAGS_MAKE_FILE_BACKUP; if (!dynamicName) - logfile = OpenFile(_filename, _mode, _backup); + logfile = OpenFile(_filename, _mode, backup); } AppenderFile::~AppenderFile() @@ -50,8 +50,7 @@ void AppenderFile::_write(LogMessage& message) if (logfile) { - fprintf(logfile, "%s %-5s [%-15s] %s", message.getTimeStr().c_str(), Appender::getLogLevelString(message.level), Appender::getLogFilterTypeString(message.type), message.text.c_str()); - + fprintf(logfile, "%s%s", message.prefix.c_str(), message.text.c_str()); fflush(logfile); if (dynamicName) diff --git a/src/server/shared/Logging/AppenderFile.h b/src/server/shared/Logging/AppenderFile.h index 8d8b0c43a54..e9cb858f625 100644 --- a/src/server/shared/Logging/AppenderFile.h +++ b/src/server/shared/Logging/AppenderFile.h @@ -23,7 +23,7 @@ class AppenderFile: public Appender { public: - AppenderFile(uint8 _id, std::string const& _name, LogLevel level, const char* filename, const char* logDir, const char* mode, bool backup); + AppenderFile(uint8 _id, std::string const& _name, LogLevel level, const char* filename, const char* logDir, const char* mode, AppenderFlags flags); ~AppenderFile(); FILE* OpenFile(std::string const& _name, std::string const& _mode, bool _backup); diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp index 2ced38847be..0bf8bcded86 100755 --- a/src/server/shared/Logging/Log.cpp +++ b/src/server/shared/Logging/Log.cpp @@ -103,7 +103,8 @@ void Log::CreateAppenderFromConfig(const char* name) { case APPENDER_CONSOLE: { - AppenderConsole* appender = new AppenderConsole(NextAppenderId(), name, level); + AppenderFlags flags = AppenderFlags(GetConfigIntDefault(base, "Flags", APPENDER_FLAGS_PREFIX_LOGLEVEL | APPENDER_FLAGS_PREFIX_LOGFILTERTYPE)); + AppenderConsole* appender = new AppenderConsole(NextAppenderId(), name, level, flags); appenders[appender->getId()] = appender; appender->InitColors(GetConfigStringDefault(base, "Colors", "")); @@ -114,10 +115,9 @@ void Log::CreateAppenderFromConfig(const char* name) { std::string filename = GetConfigStringDefault(base, "File", ""); std::string mode = GetConfigStringDefault(base, "Mode", "a"); - std::string timestamp = GetConfigStringDefault(base, "Timestamp", ""); - bool backup = GetConfigIntDefault(base, "Backup", 0); + AppenderFlags flags = AppenderFlags(GetConfigIntDefault(base, "Flags", APPENDER_FLAGS_PREFIX_TIMESTAMP | APPENDER_FLAGS_PREFIX_LOGLEVEL | APPENDER_FLAGS_PREFIX_LOGFILTERTYPE)); - if (!timestamp.empty()) + if (flags & APPENDER_FLAGS_USE_TIMESTAMP) { size_t dot_pos = filename.find_last_of("."); if (dot_pos != filename.npos) @@ -127,7 +127,7 @@ void Log::CreateAppenderFromConfig(const char* name) } uint8 id = NextAppenderId(); - appenders[id] = new AppenderFile(id, name, level, filename.c_str(), m_logsDir.c_str(), mode.c_str(), backup); + appenders[id] = new AppenderFile(id, name, level, filename.c_str(), m_logsDir.c_str(), mode.c_str(), flags); //fprintf(stdout, "Log::CreateAppenderFromConfig: Created Appender %s (%u), Type FILE, Mask %u, File %s, Mode %s\n", name, id, level, filename.c_str(), mode.c_str()); // DEBUG - RemoveMe break; } @@ -228,7 +228,6 @@ void Log::EnableDBAppenders() for (AppenderMap::iterator it = appenders.begin(); it != appenders.end(); ++it) if (it->second && it->second->getType() == APPENDER_DB) ((AppenderDB *)it->second)->setEnable(true); - } void Log::log(LogFilterType filter, LogLevel level, char const* str, ...) diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist index 614d7f95eb2..f31326b104a 100644 --- a/src/server/worldserver/worldserver.conf.dist +++ b/src/server/worldserver/worldserver.conf.dist @@ -2637,16 +2637,15 @@ PlayerDump.DisallowOverwrite = 1 # Default: a - (Append) # w - (Overwrite) # -# Appender.name.Backup -# Description: Make a backup of existing file before overwrite -# (Only used with Mode = w) -# Default: 0 - false -# 1 - true -# -# Appender.name.Timestamp -# Description: Append timestamp to the log file name. -# Logname_YYYY-MM-DD_HH-MM-SS.Ext for Logname.Ext -# (Only used with Type = 2) +# Appender.name.Flags +# Description: +# Default: Console = 6, File = 7, DB = 0 +# 0 - None +# 1 - Prefix Timestamp to the text +# 2 - Prefix Log Level to the text +# 4 - Prefix Log Filter type to the text +# 8 - Append timestamp to the log file name. Format: YYYY-MM-DD_HH-MM-SS (Only used with Type = 2) +# 16 - Make a backup of existing file before overwrite (Only used with Mode = w) # # Logger config values: Given a logger "name" the following options # can be read: -- cgit v1.2.3 From 78fdeca8518506328209654d1fa503a7cd649ff1 Mon Sep 17 00:00:00 2001 From: kaelima Date: Thu, 9 Aug 2012 12:54:35 +0200 Subject: Core/Logging: Fix crash in AppenderFile deconstructor when logfile is uninitialized --- src/server/shared/Logging/AppenderFile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/server/shared/Logging/AppenderFile.cpp') diff --git a/src/server/shared/Logging/AppenderFile.cpp b/src/server/shared/Logging/AppenderFile.cpp index d66771b9055..d47a7c4028d 100644 --- a/src/server/shared/Logging/AppenderFile.cpp +++ b/src/server/shared/Logging/AppenderFile.cpp @@ -26,8 +26,8 @@ AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, co { dynamicName = std::string::npos != filename.find("%u"); backup = _flags & APPENDER_FLAGS_MAKE_FILE_BACKUP; - if (!dynamicName) - logfile = OpenFile(_filename, _mode, backup); + + logfile = !dynamicName ? OpenFile(_filename, _mode, backup) : NULL; } AppenderFile::~AppenderFile() -- cgit v1.2.3 From ca0a54f3572e91f75f880ff9b8e74c450f7d9c36 Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 9 Aug 2012 14:31:09 +0200 Subject: Core/Logging: Fixed a possible crash with dynamic log file names --- src/server/shared/Logging/Appender.h | 2 +- src/server/shared/Logging/AppenderFile.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/server/shared/Logging/AppenderFile.cpp') diff --git a/src/server/shared/Logging/Appender.h b/src/server/shared/Logging/Appender.h index 7d7375a1edb..332edbf170c 100644 --- a/src/server/shared/Logging/Appender.h +++ b/src/server/shared/Logging/Appender.h @@ -139,7 +139,7 @@ class Appender static const char* getLogFilterTypeString(LogFilterType type); private: - virtual void _write(LogMessage& /*message*/) {}; + virtual void _write(LogMessage& /*message*/) = 0; uint8 id; std::string name; diff --git a/src/server/shared/Logging/AppenderFile.cpp b/src/server/shared/Logging/AppenderFile.cpp index d47a7c4028d..01a2f34baa7 100644 --- a/src/server/shared/Logging/AppenderFile.cpp +++ b/src/server/shared/Logging/AppenderFile.cpp @@ -26,7 +26,7 @@ AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, co { dynamicName = std::string::npos != filename.find("%u"); backup = _flags & APPENDER_FLAGS_MAKE_FILE_BACKUP; - + logfile = !dynamicName ? OpenFile(_filename, _mode, backup) : NULL; } @@ -54,7 +54,10 @@ void AppenderFile::_write(LogMessage& message) fflush(logfile); if (dynamicName) + { fclose(logfile); + logfile = NULL; + } } } -- cgit v1.2.3 From 52a5991c1258073d561e8b74ef99a7b940808d92 Mon Sep 17 00:00:00 2001 From: Spp Date: Wed, 15 Aug 2012 19:58:02 +0200 Subject: Core/Logging: Added documentation about this system - Restored old CharDump (LOG_FILTER_PLAYER_DUMP) but disabled by default. - "%s" is now used to set dynamic file names, only used by GM commands and Player dump --- doc/LoggingHOWTO.txt | 276 ++++++++++++++++++++++++++ src/server/authserver/authserver.conf.dist | 2 +- src/server/game/Handlers/CharacterHandler.cpp | 8 +- src/server/shared/Logging/Appender.h | 9 +- src/server/shared/Logging/AppenderFile.cpp | 4 +- src/server/shared/Logging/Log.cpp | 22 +- src/server/shared/Logging/Log.h | 1 + src/server/worldserver/worldserver.conf.dist | 21 +- 8 files changed, 325 insertions(+), 18 deletions(-) create mode 100644 doc/LoggingHOWTO.txt (limited to 'src/server/shared/Logging/AppenderFile.cpp') diff --git a/doc/LoggingHOWTO.txt b/doc/LoggingHOWTO.txt new file mode 100644 index 00000000000..12850eb06cf --- /dev/null +++ b/doc/LoggingHOWTO.txt @@ -0,0 +1,276 @@ +Logging system "log4j-like" + +--- LOGGERS AND APPENDERS --- + +Logging system has two components: loggers and appenders. These types of +components enable users to log messages according to message type and level and +control at runtime where they are reported. + +LOGGERS + +The first and foremost advantage of this system resided in the ability to +disable certain log statements while allowing others to print unhindered. +This capability assumes that the loggers are categorized according to some +developer-chosen criteria. + +Loggers follow hierarchy, if a logger is not defined a root logger will be used + +Loggers may be assigned levels. The set of possible levels are TRACE, DEBUG, +INFO, WARN, ERROR AND FATAL, or be disabled using level DISABLED. + +By definition the printing method determines the level of a logging request. +For example, sLog->outInfo(...) is a logging request of level INFO. + +A logging request is said to be enabled if its level is higher than or equal to +the level of its logger. Otherwise, the request is said to be disabled. A logger +without an assigned level will inherit one from the hierarchy + +Example +Logger Name Assigned Level Inherited Level +root Proot Proot +Network None Proot + +As Network is not defined, it uses the root logger and it's log level. +TRACE < DEBUG < INFO < WARN < ERROR < FATAL. + + +APPENDERS + +The ability to selectively enable of dissable logging request based on their +loggers is only part of the picture. This system allows logging requests to +print to multiple destinations. An output destination is called an appender. +Current system defines appenders for Console, files and Database, but can be +easily extended to remote socket server, NT event loggers, syslog daemons or +any other system. + +More than one appender can be attached to one logger. Each enabled logging +request for a given logger will be forwarded to all the appenders in that +logger + + +CONFIGURATION + +System will read "Loggers" and "Appenders" to know the list of loggers and +appenders to read from config file. Both are a list of elements separated +by space. + +Once we have the list of appenders to read, system will try to configure a new +appender from its config line. Appender config line follows the format: + + Type,LogLevel,Flags,optional1,optional2 + +Its a list of elements separated by comma where each element has its own meaning + Type: Type of the appender + 1 - (Console) + 2 - (File) + 3 - (DB) + LogLevel: Log level + 0 - (Disabled) + 1 - (Trace) + 2 - (Debug) + 3 - (Info) + 4 - (Warn) + 5 - (Error) + 6 - (Fatal) + Flags: Define some extra modifications to do to logging message + 1 - Prefix Timestamp to the text + 2 - Prefix Log Level to the text + 4 - Prefix Log Filter type to the text + 8 - Append timestamp to the log file name. Format: YYYY-MM-DD_HH-MM-SS + (Only used with Type = 2) + 16 - Make a backup of existing file before overwrite + (Only used with Mode = w) + +Depending on the type, elements optional1 and optional2 will take different + + Colors (read as optional1 if Type = Console) + Format: "fatal error warn info debug trace" + 0 - BLACK + 1 - RED + 2 - GREEN + 3 - BROWN + 4 - BLUE + 5 - MAGENTA + 6 - CYAN + 7 - GREY + 8 - YELLOW + 9 - LRED + 10 - LGREEN + 11 - LBLUE + 12 - LMAGENTA + 13 - LCYAN + 14 - WHITE + Example: "13 11 9 5 3 1" + + File: Name of the file (read as optional1 if Type = File) + Allows to use one "%u" to create dynamic files + + Mode: Mode to open the file (read as optional2 if Type = File) + a - (Append) + w - (Overwrite) + +Example: + Appender.Console1=1,2,6 + + Creates new appender to log to console any message with log level DEBUG + or higher and prefixes log type and level to the message. + + Appender.Console2=1,5,1,13 11 9 5 3 1 + + Creates new appender to log to console any message with log level ERROR + or higher and prefixes timestamp to the message using colored text. + + Appender.File=2,2,7,Auth.log,w + + Creates new appender to log to file "Auth.log" any message with log level + DEBUG or higher and prefixes timestamp, type and level to message + +In the example, having two different loggers to log to console is perfectly +legal but redundant. + +Once we have the list of loggers to read, system will try to configure a new +logger from its config line. Logger config line follows the format: + + Type,LogLevel,AppenderList + +Its a list of elements separated by comma where each element has its own meaning + Type: Type of the logger ( + 0 - Default. Each type that has no config will + rely on this one. Core will create this logger + (disabled) if it's not configured + 1 - Units that doesn't fit in other categories + 2 - Pets + 3 - Vehicles + 4 - C++ AI, instance scripts, etc. + 5 - DB AI, such as SAI, EAI, CreatureAI + 6 - DB map scripts + 7 - Network input/output, + such as packet handlers and netcode logs + 8 - Spellsystem and aurasystem + 9 - Achievement system + 10 - Condition system + 11 - Pool system + 12 - Auction house + 13 - Arena's and battlegrounds + 14 - Outdoor PVP + 15 - Chat system + 16 - LFG system + 17 - Maps, instances (not scripts), + grids, cells, visibility, etc. + 18 - Player that doesn't fit in other categories. + 19 - Player loading from DB + (Player::_LoadXXX functions) + 20 - Items + 21 - Player skills (do not confuse with spells) + 22 - Player chat logs + 23 - loot + 24 - guilds + 25 - transports + 26 - SQL. DB errors + 27 - GM Commands + 28 - Remote Access Commands + 29 - Warden + 30 - Authserver + 31 - Worldserver + 32 - Game Events + 33 - Calendar + 34 - Character (Exclusive to login, logout, create, rename and delete) + 35 - Arenas + 36 - SQL Driver + 37 - SQL Dev + LogLevel + 0 - (Disabled) + 1 - (Trace) + 2 - (Debug) + 3 - (Info) + 4 - (Warn) + 5 - (Error) + 6 - (Fatal) + AppenderList: List of appenders linked to logger + (Using spaces as separator). + +--- EXAMPLES --- + +EXAMPLE 1 + +Log errors to console and a file called server.log that only contain +logs for this server run. File should prefix timestamp, type and log level to +the messages. Console should prefix type and log level. + + Appenders=Console Server + Loggers=Root + Appender.Console=1,5,6 + Appender.Server=2,5,7,Server.log,w + Logger.Root=0,5,Console Server + +Lets trace how system will log two different messages: + 1) sLog->outError(LOG_FILTER_GUILD, "Guild 1 created"); + System will try to find logger of type GUILD, as no logger is configured + for GUILD it will use Root logger. As message Log Level is equal or higher + than the Log level of logger the message is sent to the Appenders + configured in the Logger. "Console" and "Server". + Console will write: "ERROR [GUILD ] Guild 1 created" + Server will write to file "2012-08-15 ERROR [GUILD ] Guild 1 created" + + 2) sLog->outInfo(LOG_FILTER_CHARACTER, "Player Name Logged in"); + System will try to find logger of type CHARACTER, as no logger is + configured for CHARACTER it will use Root logger. As message Log Level is + not equal or higher than the Log level of logger the message its discarted. + +EXAMPLE 2 + +Same example that above, but now i want to see all messages of level INFO on +file and server file should add timestamp on creation. + + Appenders=Console Server + Loggers=Root + Appender.Console=1,5,6 + Appender.Server=2,4,15,Server.log + Logger.Root=0,4,Console Server + +Lets trace how system will log two different messages: + 1) sLog->outError(LOG_FILTER_GUILD, "Guild 1 created"); + Performs exactly as example 1. + 2) sLog->outInfo(LOG_FILTER_CHARACTER, "Player Name Logged in"); + System will try to find logger of type CHARACTER, as no logger is + configured for CHARACTER it will use Root logger. As message Log Level is + equal or higher than the Log level of logger the message is sent to the + Appenders configured in the Logger. "Console" and "Server". + Console will discard msg as Log Level is not higher or equal to this + appender + Server will write to file + "2012-08-15 INFO [CHARACTER ] Guild 1 Player Name Logged in" + +EXAMPLE 3 +As a dev, i may be interested in logging just a particular part of the core +while i'm trying to fix something. So... i want to debug GUILDS to maximum +and also some CHARACTER events to some point. Also im checking some Waypoints +so i want SQLDEV to be logged to file without prefixes. All other messages +should only be logged to console, GUILD to TRACE and CHARACTER to INFO + + Appenders=Console SQLDev + Loggers=Guild Characters SQLDev + Appender.Console=1,1 + Appender.SQLDev=2,2,0,SQLDev.log + Logger.Guild=24,1,Console + Logger.Characters=34,3,Console + Logger.SQLDev=37,3,SQLDev + +With this config, any message logger with a Log type different to GUILD, +CHARACTER or SQLDEV will be ignored, as we didn't define a logger Root and +system created a default Root disabled. Appender Console, log level should be +defined to allow all possible messages of its loggers, in this case GUILD uses +TRACE (1), so Appender should allow it. Logger Characters will limit it's own +messages to INFO (3) + +--- SOME EXTRA COMMENTS --- +why this system is better than previous one? +- Can be extended: Anyone can easily create new appenders to log to new + systems as syslog or IRC, having all code related to that system in particular + files +- It's asyncronous: Uses threads to write messages, so core performance wont be + affected by IO operations +- Lets us select "What to log" and "Where to log" on the fly. You can log to a + dozen of files without having to change a single line of code + + \ No newline at end of file diff --git a/src/server/authserver/authserver.conf.dist b/src/server/authserver/authserver.conf.dist index d1c92dcf1d0..15dd02d9052 100644 --- a/src/server/authserver/authserver.conf.dist +++ b/src/server/authserver/authserver.conf.dist @@ -170,7 +170,7 @@ LoginDatabase.WorkerThreads = 1 # 5 - (Error) # 6 - (Fatal) # -# Flags: Default Console = 6, File = 7, DB = 0 +# Flags: # 0 - None # 1 - Prefix Timestamp to the text # 2 - Prefix Log Level to the text diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index 7451bd2dc2a..8544266840f 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -719,11 +719,15 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket & recv_data) sScriptMgr->OnPlayerDelete(guid); sWorld->DeleteCharaceterNameData(GUID_LOPART(guid)); - if (sLog->ShouldLog(LOG_FILTER_CHARACTER, LOG_LEVEL_DEBUG)) // optimize GetPlayerDump call + if (sLog->ShouldLog(LOG_FILTER_PLAYER_DUMP, LOG_LEVEL_INFO)) // optimize GetPlayerDump call { std::string dump; if (PlayerDumpWriter().GetDump(GUID_LOPART(guid), dump)) - sLog->outDebug(LOG_FILTER_CHARACTER, dump.c_str(), GetAccountId(), GUID_LOPART(guid), name.c_str()); + { + std::ostringstream ss; + ss << GetAccountId() << '_' << name.c_str(); + sLog->outCharDump(ss.str().c_str(), dump.c_str(), GetAccountId(), GUID_LOPART(guid), name.c_str()); + } } Player::DeleteFromDB(guid, GetAccountId()); diff --git a/src/server/shared/Logging/Appender.h b/src/server/shared/Logging/Appender.h index 332edbf170c..ebe7408d400 100644 --- a/src/server/shared/Logging/Appender.h +++ b/src/server/shared/Logging/Appender.h @@ -62,10 +62,12 @@ enum LogFilterType LOG_FILTER_CHARACTER, LOG_FILTER_ARENAS, LOG_FILTER_SQL_DRIVER, - LOG_FILTER_SQL_DEV + LOG_FILTER_SQL_DEV, + LOG_FILTER_PLAYER_DUMP, + LOG_FILTER_BATTLEFIELD }; -const uint8 MaxLogFilter = uint8(LOG_FILTER_SQL_DEV) + 1; +const uint8 MaxLogFilter = uint8(LOG_FILTER_BATTLEFIELD) + 1; // Values assigned have their equivalent in enum ACE_Log_Priority enum LogLevel @@ -105,7 +107,6 @@ struct LogMessage : level(_level) , type(_type) , text(_text) - , param1(0) { mtime = time(NULL); } @@ -117,7 +118,7 @@ struct LogMessage LogFilterType type; std::string text; std::string prefix; - uint32 param1; + std::string param1; time_t mtime; }; diff --git a/src/server/shared/Logging/AppenderFile.cpp b/src/server/shared/Logging/AppenderFile.cpp index 01a2f34baa7..67adff39aae 100644 --- a/src/server/shared/Logging/AppenderFile.cpp +++ b/src/server/shared/Logging/AppenderFile.cpp @@ -24,7 +24,7 @@ AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, co , logDir(_logDir) , mode(_mode) { - dynamicName = std::string::npos != filename.find("%u"); + dynamicName = std::string::npos != filename.find("%s"); backup = _flags & APPENDER_FLAGS_MAKE_FILE_BACKUP; logfile = !dynamicName ? OpenFile(_filename, _mode, backup) : NULL; @@ -44,7 +44,7 @@ void AppenderFile::_write(LogMessage& message) if (dynamicName) { char namebuf[TRINITY_PATH_MAX]; - snprintf(namebuf, TRINITY_PATH_MAX, filename.c_str(), message.param1); + snprintf(namebuf, TRINITY_PATH_MAX, filename.c_str(), message.param1.c_str()); logfile = OpenFile(namebuf, mode, backup); } diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp index 27f33754da9..64f7e697f1f 100755 --- a/src/server/shared/Logging/Log.cpp +++ b/src/server/shared/Logging/Log.cpp @@ -449,6 +449,23 @@ void Log::outFatal(LogFilterType filter, const char * str, ...) va_end(ap); } +void Log::outCharDump(const char* param, const char * str, ...) +{ + if (!str || !ShouldLog(LOG_FILTER_PLAYER_DUMP, LOG_LEVEL_INFO)) + return; + + va_list ap; + va_start(ap, str); + char text[MAX_QUERY_LEN]; + vsnprintf(text, MAX_QUERY_LEN, str, ap); + va_end(ap); + + LogMessage* msg = new LogMessage(LOG_LEVEL_INFO, LOG_FILTER_PLAYER_DUMP, text); + msg->param1 = param; + + write(msg); +} + void Log::outCommand(uint32 account, const char * str, ...) { if (!str || !ShouldLog(LOG_FILTER_GMCOMMAND, LOG_LEVEL_INFO)) @@ -461,7 +478,10 @@ void Log::outCommand(uint32 account, const char * str, ...) va_end(ap); LogMessage* msg = new LogMessage(LOG_LEVEL_INFO, LOG_FILTER_GMCOMMAND, text); - msg->param1 = account; + + std::ostringstream ss; + ss << account; + msg->param1 = ss.str(); write(msg); } diff --git a/src/server/shared/Logging/Log.h b/src/server/shared/Logging/Log.h index 7b0e8cd381b..cd1e9dc80df 100755 --- a/src/server/shared/Logging/Log.h +++ b/src/server/shared/Logging/Log.h @@ -56,6 +56,7 @@ class Log void EnableDBAppenders(); void outCommand(uint32 account, const char * str, ...) ATTR_PRINTF(3, 4); + void outCharDump(const char* param, const char* str, ...) ATTR_PRINTF(3, 4); static std::string GetTimestampStr(); void SetRealmID(uint32 id); diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist index be5a452c7b4..789af4e371b 100644 --- a/src/server/worldserver/worldserver.conf.dist +++ b/src/server/worldserver/worldserver.conf.dist @@ -2592,7 +2592,7 @@ PlayerDump.DisallowOverwrite = 1 # 5 - (Error) # 6 - (Fatal) # -# Flags: Default Console = 6, File = 7, DB = 0 +# Flags: # 0 - None # 1 - Prefix Timestamp to the text # 2 - Prefix Log Level to the text @@ -2629,13 +2629,14 @@ PlayerDump.DisallowOverwrite = 1 Appender.Console=1,2,6 Appender.Server=2,2,7,Server.log,w -Appender.GM=2,2,7,GM.log +Appender.GM=2,2,7,GM_%s.log Appender.SQL=2,2,7,SQL.log Appender.DBErrors=2,2,7,DBErrors.log Appender.Char=2,2,7,Char.log,w +Appender.CharDump=2,2,0,chardumps/%s.log Appender.RA=2,2,7,RA.log Appender.Arenas=2,2,7,Arena.log -Appender.SQLDev=2,2,7,SQLDev.log +Appender.SQLDev=2,2,0,SQLDev.log Appender.SQLDriver=2,2,7,SQLDriver.log Appender.Warden=2,2,7,Warden.log Appender.Chat=2,2,7,Chat.log @@ -2684,12 +2685,14 @@ Appender.Chat=2,2,7,Chat.log # 31 - Worldserver # 32 - Game Events # 33 - Calendar -# 34 - Character (Exclusive to log login, logout, create, rename, delete actions) +# 34 - Character (Exclusive to log login, logout, create, rename) # 35 - Arenas # 36 - SQL Driver # 37 - SQL Dev +# 38 - Player Dump +# 39 - Battlefield -Logger.Root=0,5,Console Server +Logger.Root=0,3,Console Server Logger.Units=1,3,Console Server Logger.Pets=2,3,Console Server Logger.Vehicles=3,3,Console Server @@ -2715,7 +2718,7 @@ Logger.PlayerChat=22,3,Chat Logger.Loot=23,3,Console Server Logger.Guilds=24,3,Console Server Logger.Transports=25,3,Console Server -Logger.SQL=26,2,Console Server SQL +Logger.SQL=26,2,Console Server DBErrors Logger.GM=27,3,Console Server GM Logger.RA=28,3,RA Logger.Warden=29,3,Warden @@ -2727,6 +2730,8 @@ Logger.Character=34,3,Char Logger.Arenas=35,3,Arenas Logger.SQLDriver=36,5,SQLDriver Logger.SQLDev=37,3,SQLDev +Logger.CharDump=38,5,CharDump +Logger.Battlefield=39,3,Console Server # LogLevel # 0 - (Disabled) @@ -2745,7 +2750,7 @@ Logger.SQLDev=37,3,SQLDev # (Using spaces as separator). # Default: "Console Server" -Appenders=Console Server +Appenders=Console Server GM Char Arenas Warden DBErrors CharDump # # Loggers @@ -2753,4 +2758,4 @@ Appenders=Console Server # (Using spaces as separator). # Default: "root" -Loggers=Root +Loggers=Root GM Character Arenas Warden SQL -- cgit v1.2.3