Standard logging facilities (interface). More...
#include <iosfwd>
#include <sstream>
#include <string>
#include <utility>
#include <ctime>
#include "formatter.hpp"
Go to the source code of this file.
Classes | |
class | lg::redirect_output_setter |
Helper class to redirect the output of the logger in a certain scope. More... | |
class | lg::log_domain |
class | lg::log_in_progress |
class | lg::logger |
class | lg::scope_logger |
Namespaces | |
lg | |
Macros | |
#define | log_scope(description) lg::scope_logger scope_logging_object__(lg::general(), description); |
#define | log_scope2(domain, description) lg::scope_logger scope_logging_object__(domain, description); |
#define | LOG_STREAM(level, domain) if (lg::level().dont_log(domain)) ; else lg::level()(domain) | formatter() |
#define | LOG_STREAM_NAMELESS(level, domain) if (lg::level().dont_log(domain)) ; else lg::level()(domain, false) | formatter() |
#define | LOG_STREAM_NAMELESS_STREAMING(level, domain) if (lg::level().dont_log(domain)) ; else lg::level()(domain, false, false, true, true, false) | formatter() |
#define | LOG_STREAM_INDENT(level, domain) if (lg::level().dont_log(domain)) ; else lg::level()(domain, true, true) | formatter() |
#define | FORCE_LOG_TO(logger, domain) logger(domain) | formatter() |
#define | PLAIN_LOG lg::err()(lg::general(), false, false, false, false, true) | formatter() |
#define | STREAMING_LOG lg::err()(lg::general(), false, false, false, false, false) | formatter() |
Typedefs | |
typedef std::pair< const std::string, int > | lg::logd |
Enumerations | |
enum | lg::severity { lg::LG_ERROR =0, lg::LG_WARN =1, lg::LG_INFO =2, lg::LG_DEBUG =3 } |
Functions | |
bool | lg::set_log_domain_severity (const std::string &name, int severity) |
bool | lg::set_log_domain_severity (const std::string &name, const logger &lg) |
bool | lg::get_log_domain_severity (const std::string &name, int &severity) |
std::string | lg::list_logdomains (const std::string &filter) |
void | lg::set_strict_severity (int severity) |
void | lg::set_strict_severity (const logger &lg) |
bool | lg::broke_strict () |
void | lg::set_log_to_file () |
void | lg::check_log_dir_writable () |
bool | lg::log_dir_writable () |
bool | lg::is_not_log_file (const std::string &fn) |
Helper function for rotate_logs. More... | |
void | lg::rotate_logs (const std::string &log_dir) |
Deletes old log files from the log directory. More... | |
std::string | lg::unique_log_filename () |
Generates a unique log file name. More... | |
void | lg::timestamps (bool t) |
void | lg::precise_timestamps (bool pt) |
std::string | lg::get_timestamp (const std::time_t &t, const std::string &format) |
std::string | lg::get_timespan (const std::time_t &t) |
std::string | lg::sanitize_log (const std::string &logstr) |
std::string & | lg::get_log_file_path () |
void | lg::set_log_file_path (const std::string &path) |
logger & | lg::err () |
logger & | lg::warn () |
logger & | lg::info () |
logger & | lg::debug () |
log_domain & | lg::general () |
std::stringstream & | lg::log_to_chat () |
Use this to show WML errors in the ingame chat. More... | |
Variables | |
const std::string | lg::log_file_prefix = "wesnoth-" |
const std::string | lg::log_file_suffix = ".log" |
const unsigned | lg::max_logs = 8 |
Standard logging facilities (interface).
To use one of the standard log channels, put something like the following at the start of your .cpp file:
static lg::log_domain log_display("display"); #define ERR_DP LOG_STREAM(err, log_display) #define LOG_DP LOG_STREAM(info, log_display)
Then stream logging info to ERR_DP, or LOG_DP, as if it were an ostream like std::cerr. (In general it will actually be std::cerr at runtime when logging is enabled.)
LOG_DP << "Found a window resize event: ...";
Please do not use iomanip features like std::hex directly on the logger. Because of the design of the logger, this will result in all of the loggers (in fact std::cerr) being imbued with std::hex. Please use a formatter instead.
#include "formatter.hpp"
LOG_DP << (formatter() << "The random seed is: '" << std::hex << seed << "'\n").str();
It might be nice if somehow the logger class / macros could support using iomanip things directly, but right now it doesn't, and it seems that it would complicate the design greatly enough that it doesn't seem worth it.
Definition in file log.hpp.
#define FORCE_LOG_TO | ( | logger, | |
domain | |||
) | logger(domain) | formatter() |
Definition at line 255 of file log.hpp.
Referenced by deprecated_message(), game_config_manager::load_game_config_with_loadscreen(), and game_events::wml_event_pump::put_wml_message().
#define log_scope | ( | description | ) | lg::scope_logger scope_logging_object__(lg::general(), description); |
Definition at line 239 of file log.hpp.
Referenced by unit::apply_modifications(), playsingle_controller::before_human_turn(), terrain_builder::build_terrains(), default_map_generator_job::default_generate_map(), savegame::save_index_class::delete_game(), savegame::save_index_class::delete_old_auto_saves(), play_controller::do_init_side(), do_replay(), game_lua_kernel::intf_add_time_area(), game_lua_kernel::intf_remove_time_area(), savegame::loadgame::load_multiplayer_game(), lua_mapgen::filter::matches(), terrain_builder::parse_config(), preprocess_file(), game_config::config_cache::read_cache(), savegame::save_index_class::rebuild(), saved_game::set_data(), help::help_browser::show_topic(), unit_display::unit_attack(), savegame::savegame::write_game(), savegame::ingame_savegame::write_game(), and savegame::save_index_class::write_save_index().
#define log_scope2 | ( | domain, | |
description | |||
) | lg::scope_logger scope_logging_object__(domain, description); |
Definition at line 240 of file log.hpp.
Referenced by gui2::builder_grid::build(), gui2::builder_grid::builder_grid(), gui2::slider::calculate_best_size(), gui2::container_base::calculate_best_size(), gui2::scrollbar_container::calculate_best_size(), gui2::grid::calculate_best_size(), gui2::tree_view_node::calculate_best_size(), battle_context::choose_attacker_weapon(), battle_context::choose_defender_weapon(), ai::ai_default_rca::move_to_targets_phase::choose_move(), gui2::dialogs::dump_recall_list_to_console(), ai::default_ai_context_impl::find_targets(), gui2::grid::child::get_best_size(), gui2::styled_widget::get_best_text_size(), gui2::container_base::init_grid(), gui2::window_implementation::layout(), gui2::window::layout(), game_config_manager::load_addons_cfg(), editor::map_context::map_context(), gui2::canvas::parse_cfg(), gui2::grid::place(), gui2::tree_view_node::place(), gui2::grid::reduce_height(), gui2::grid::reduce_width(), wb::manager::set_planned_unit_map(), wb::manager::set_real_unit_map(), gui2::tree_view_node::set_visible_rectangle(), gui2::window::show(), gui2::window::show_non_modal(), and gui2::window::show_tooltip().
#define LOG_STREAM | ( | level, | |
domain | |||
) | if (lg::level().dont_log(domain)) ; else lg::level()(domain) | formatter() |
Definition at line 242 of file log.hpp.
Referenced by ai::typesafe_known_aspect< T >::add_facet(), deprecated_message(), intf_log(), ai::typesafe_known_aspect< T >::set(), gui2::show_error_message(), gui2::show_transient_error_message(), and ai::standard_aspect< config >::standard_aspect().
#define LOG_STREAM_INDENT | ( | level, | |
domain | |||
) | if (lg::level().dont_log(domain)) ; else lg::level()(domain, true, true) | formatter() |
#define LOG_STREAM_NAMELESS | ( | level, | |
domain | |||
) | if (lg::level().dont_log(domain)) ; else lg::level()(domain, false) | formatter() |
#define LOG_STREAM_NAMELESS_STREAMING | ( | level, | |
domain | |||
) | if (lg::level().dont_log(domain)) ; else lg::level()(domain, false, false, true, true, false) | formatter() |
#define PLAIN_LOG lg::err()(lg::general(), false, false, false, false, true) | formatter() |
Definition at line 260 of file log.hpp.
Referenced by adjust_surface_alpha_add(), adjust_surface_color(), alpha_to_greyscale(), combatant::average_hp(), blend_surface(), blur_alpha_surface(), blur_surface(), BOOST_AUTO_TEST_CASE(), brighten_image(), cut_surface(), decode(), do_gameloop(), gui::scrollbar::draw_contents(), encode(), wfl::formula::execute(), wfl::operator_expression::execute(), combatant::fight(), campaignd::server::fire(), flip_surface(), flop_surface(), game_launcher::game_launcher(), help::generate_contents(), video::get_available_resolutions(), get_non_transparent_portion(), get_surface_portion(), greyscale_image(), campaignd::server::handle_delete(), handle_lua_script_args(), handle_preprocess_command(), handle_validate_command(), gui2::event::dispatcher::has_event(), in_mask_surface(), game_launcher::init_language(), game_launcher::init_lua_script(), game_launcher::init_video(), video::init_window(), gui2::dialogs::lua_interpreter::input_model::input_model(), intf_describe_plugins(), light_surface(), load_strings(), main(), help::make_unit_link(), mask_surface(), monochrome_image(), gui2::scrollbar_base::move_positioner(), negative_image(), image::adjust_alpha_modification::operator()(), image::adjust_channels_modification::operator()(), image::o_modification::operator()(), terrain_builder::parse_config(), help::parse_config_internal(), commandline_options::parse_log_strictness(), gui2::widget::place(), game_launcher::play_multiplayer(), game_launcher::play_render_image_mode(), game_launcher::play_test(), process_command_args(), gui2::scrollbar_base::recalculate(), recolor_image(), rotate_180_surface(), rotate_90_surface(), run_campaignd(), scale_surface(), scale_surface_legacy(), scale_surface_nn(), scale_surface_sharp(), scale_surface_xbrz(), ng::create_engine::select_campaign_difficulty(), sepia_image(), wfl::formula_callable::set_value(), shadow_image(), help::help_browser::show_topic(), game_launcher::single_unit_test(), mp::start_local_game_commandline(), swap_channels_image(), t_translation::terrain_matches(), wfl::type_error::type_error(), unicode_cast(), game_launcher::unit_test(), warn_early_init_failure(), wipe_alpha(), and save_blocker::~save_blocker().
#define STREAMING_LOG lg::err()(lg::general(), false, false, false, false, false) | formatter() |
Definition at line 261 of file log.hpp.
Referenced by check_fpu(), ai::ai_default_rca::get_villages_phase::dispatch_complex(), ai::ai_default_rca::get_villages_phase::dump_reachmap(), and game_launcher::init_lua_script().