Standard logging facilities (implementation). More...
#include "log.hpp"
#include "filesystem.hpp"
#include "mt_rng.hpp"
#include "serialization/chrono.hpp"
#include "serialization/string_utils.hpp"
#include "utils/general.hpp"
#include <boost/algorithm/string.hpp>
#include <map>
#include <ctime>
#include <mutex>
#include <iostream>
#include <iomanip>
Go to the source code of this file.
Namespaces | |
lg | |
Macros | |
#define | ERR_LS LOG_STREAM(err, log_setup) |
#define | WRN_LS LOG_STREAM(warn, log_setup) |
#define | LOG_LS LOG_STREAM(info, log_setup) |
#define | DBG_LS LOG_STREAM(debug, log_setup) |
Typedefs | |
typedef std::map< std::string, severity > | lg::domain_map |
Functions | |
static std::ostream | null_ostream (new null_streambuf) |
static std::ostream & | output () |
std::ostringstream & | lg::operator<< (std::ostringstream &oss, const lg::severity severity) |
bool | lg::is_not_log_file (const std::string &filename) |
Use the defined prefix and suffix to determine if a filename is a log file. More... | |
void | lg::rotate_logs (const std::string &log_dir) |
Check how many log files exist and delete the oldest when there's too many. More... | |
std::string | lg::unique_log_filename () |
Generate a unique file name using the current timestamp and a randomly generated number. More... | |
void | lg::check_log_dir_writable () |
Checks that a dummy file can be written to and deleted from the logs directory. More... | |
void | lg::move_log_file () |
Move the log file to another directory. More... | |
void | lg::set_log_to_file () |
Do the initial redirection to a log file if the logs directory is writable. More... | |
utils::optional< bool > | lg::log_dir_writable () |
Returns the result set by check_log_dir_writable(). More... | |
std::string | lg::get_log_file_path () |
void | lg::timestamps (bool t) |
void | lg::precise_timestamps (bool pt) |
logger & | lg::err () |
logger & | lg::warn () |
logger & | lg::info () |
logger & | lg::debug () |
log_domain & | lg::general () |
bool | lg::set_log_domain_severity (const std::string &name, severity severity) |
bool | lg::set_log_domain_severity (const std::string &name, const logger &lg) |
bool | lg::get_log_domain_severity (const std::string &name, severity &severity) |
std::string | lg::list_log_domains (const std::string &filter) |
void | lg::set_strict_severity (severity severity) |
void | lg::set_strict_severity (const logger &lg) |
bool | lg::broke_strict () |
std::string | lg::format_timespan (const std::chrono::seconds &span) |
TODO: we also have utils::format_timespan, which does something very similar... More... | |
void | lg::set_log_sanitize (bool sanitize) |
toggle log sanitization More... | |
std::string | lg::sanitize_log (const std::string &logstr) |
std::stringstream & | lg::log_to_chat () |
Use this to show WML errors in the ingame chat. More... | |
Variables | |
static lg::log_domain | log_setup ("logsetup") |
static int | indent = 0 |
static bool | timestamp = true |
static bool | precise_timestamp = false |
static std::mutex | log_mutex |
static bool | log_sanitization = true |
static utils::optional< bool > | is_log_dir_writable_ = utils::nullopt |
whether the current logs directory is writable More... | |
static std::ostream * | output_stream_ = nullptr |
alternative stream to write data to More... | |
static std::string | output_file_path_ = "" |
path to the current log file; does not include the extension More... | |
static std::string | logs_dir_ = "" |
path to the current logs directory; may change after being initially set if a custom userdata directory is given on the command line More... | |
static domain_map * | lg::domains |
static severity | lg::strict_level_ = severity::LG_NONE |
static log_domain | lg::dom ("general") |
static bool | lg::strict_threw_ = false |
Standard logging facilities (implementation).
See also the command line switches –logdomains and –log-<level>="domain".
Definition in file log.cpp.
#define DBG_LS LOG_STREAM(debug, log_setup) |
#define ERR_LS LOG_STREAM(err, log_setup) |
#define LOG_LS LOG_STREAM(info, log_setup) |
#define WRN_LS LOG_STREAM(warn, log_setup) |
|
static |
Referenced by lg::logger::operator()().
|
static |
Definition at line 75 of file log.cpp.
References output_stream_.
Referenced by _crypt_output_magic(), BF_crypt(), BOOST_AUTO_TEST_CASE(), wfl::builtins::DEFINE_WFL_FUNCTION(), lg::scope_logger::do_log_exit(), display::draw_hex(), lg::logger::operator()(), php_crypt_blowfish_rn(), and tod_manager::resolve_random().
|
static |
Definition at line 60 of file log.cpp.
Referenced by lg::scope_logger::do_log_entry(), lg::scope_logger::do_log_exit(), wfl::formula_function_expression::execute(), lg::logger::operator()(), lg::log_in_progress::operator|(), and gui2::dialogs::formula_debugger::pre_show().
|
static |
whether the current logs directory is writable
Definition at line 68 of file log.cpp.
Referenced by lg::check_log_dir_writable(), lg::log_dir_writable(), lg::move_log_file(), and lg::set_log_to_file().
|
static |
Definition at line 63 of file log.cpp.
Referenced by lg::log_in_progress::operator|().
|
static |
Definition at line 65 of file log.cpp.
Referenced by lg::sanitize_log(), and lg::set_log_sanitize().
|
static |
|
static |
path to the current logs directory; may change after being initially set if a custom userdata directory is given on the command line
Definition at line 86 of file log.cpp.
Referenced by lg::move_log_file(), and lg::set_log_to_file().
|
static |
path to the current log file; does not include the extension
Definition at line 84 of file log.cpp.
Referenced by lg::get_log_file_path(), lg::move_log_file(), lg::rotate_logs(), and lg::set_log_to_file().
|
static |
alternative stream to write data to
Definition at line 70 of file log.cpp.
Referenced by output(), lg::redirect_output_setter::redirect_output_setter(), and lg::redirect_output_setter::~redirect_output_setter().
|
static |
Definition at line 62 of file log.cpp.
Referenced by lg::log_in_progress::operator|(), and lg::precise_timestamps().
|
static |
Definition at line 61 of file log.cpp.
Referenced by editor::editor_controller::custom_tods_dialog(), lg::scope_logger::do_log_exit(), editor::initialize_addon(), lg::logger::operator()(), gui2::dialogs::chat_log::model::stream_log(), and lg::timestamps().