The Battle for Wesnoth  1.19.0-dev
Namespaces | Macros | Typedefs | Functions | Variables
log.cpp File Reference

Standard logging facilities (implementation). More...

#include "log.hpp"
#include "filesystem.hpp"
#include "mt_rng.hpp"
#include <boost/algorithm/string.hpp>
#include <map>
#include <ctime>
#include <mutex>
#include <iostream>
#include <iomanip>
Include dependency graph for log.cpp:

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...
 
std::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::get_timestamp (const std::time_t &t, const std::string &format)
 
std::string lg::get_timespan (const std::time_t &t)
 
static void lg::print_precise_timestamp (std::ostream &out) noexcept
 
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 std::optional< bool > is_log_dir_writable_ = std::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
 

Detailed Description

Standard logging facilities (implementation).

See also the command line switches –logdomains and –log-<level>="domain".

Definition in file log.cpp.

Macro Definition Documentation

◆ DBG_LS

#define DBG_LS   LOG_STREAM(debug, log_setup)

Definition at line 43 of file log.cpp.

◆ ERR_LS

#define ERR_LS   LOG_STREAM(err, log_setup)

Definition at line 40 of file log.cpp.

◆ LOG_LS

#define LOG_LS   LOG_STREAM(info, log_setup)

Definition at line 42 of file log.cpp.

◆ WRN_LS

#define WRN_LS   LOG_STREAM(warn, log_setup)

Definition at line 41 of file log.cpp.

Function Documentation

◆ null_ostream()

static std::ostream null_ostream ( new  null_streambuf)
static

Referenced by lg::logger::operator()().

◆ output()

static std::ostream& output ( )
static
Returns
std::cerr if the redirect_output_setter isn't being used, output_stream_ if it is

Definition at line 70 of file log.cpp.

References output_stream_.

Referenced by _crypt_output_magic(), BF_crypt(), 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().

Variable Documentation

◆ indent

int indent = 0
static

◆ is_log_dir_writable_

std::optional<bool> is_log_dir_writable_ = std::nullopt
static

whether the current logs directory is writable

Definition at line 63 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().

◆ log_mutex

std::mutex log_mutex
static

Definition at line 60 of file log.cpp.

Referenced by lg::log_in_progress::operator|().

◆ log_setup

lg::log_domain log_setup("logsetup") ( "logsetup"  )
static

◆ logs_dir_

std::string logs_dir_ = ""
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 81 of file log.cpp.

Referenced by lg::move_log_file(), and lg::set_log_to_file().

◆ output_file_path_

std::string output_file_path_ = ""
static

path to the current log file; does not include the extension

Definition at line 79 of file log.cpp.

Referenced by lg::get_log_file_path(), lg::move_log_file(), lg::rotate_logs(), and lg::set_log_to_file().

◆ output_stream_

std::ostream* output_stream_ = nullptr
static

alternative stream to write data to

Definition at line 65 of file log.cpp.

Referenced by output(), lg::redirect_output_setter::redirect_output_setter(), and lg::redirect_output_setter::~redirect_output_setter().

◆ precise_timestamp

bool precise_timestamp = false
static

Definition at line 59 of file log.cpp.

Referenced by lg::log_in_progress::operator|(), and lg::precise_timestamps().

◆ timestamp

bool timestamp = true
static