Standard logging facilities (interface). More...
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <boost/date_time/posix_time/posix_time_types.hpp>
Go to the source code of this file.
Classes | |
class | lg::tredirect_output_setter |
Helper class to redirect the output of the logger in a certain scope. More... | |
class | lg::log_domain |
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) |
#define | LOG_STREAM_INDENT(level, domain) if (lg::level().dont_log(domain)) ; else lg::level()(domain, true, true) |
Typedefs | |
typedef std::pair< const std::string, int > | lg::logd |
Functions | |
bool | lg::set_log_domain_severity (std::string const &name, int severity) |
bool | lg::set_log_domain_severity (std::string const &name, const logger &lg) |
bool | lg::get_log_domain_severity (std::string const &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::timestamps (bool t) |
void | lg::precise_timestamps (bool pt) |
std::string | lg::get_timestamp (const time_t &t, const std::string &format) |
std::string | lg::get_timespan (const time_t &t) |
logger & | lg::err () |
logger & | lg::warn () |
logger & | lg::info () |
logger & | lg::debug () |
log_domain & | lg::general () |
std::stringstream & | lg::wml_error () |
Use this logger to send errors due to deprecated WML. More... | |
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: ...\n";
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 log_scope | ( | description | ) | lg::scope_logger scope_logging_object__(lg::general(), description); |
Definition at line 185 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(), 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(), 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 186 of file log.hpp.
Referenced by gui2::tbuilder_grid::build(), gui2::tslider::calculate_best_size(), gui2::tcontainer_::calculate_best_size(), gui2::tscrollbar_container::calculate_best_size(), gui2::tgrid::calculate_best_size(), gui2::ttree_view_node::calculate_best_size(), ai::ai_default_rca::move_to_targets_phase::choose_move(), gui2::tcanvas::draw(), ai::default_ai_context_impl::find_targets(), gui2::tgrid::tchild::get_best_size(), gui2::tcontrol::get_best_text_size(), gui2::tcontainer_::init_grid(), gui2::twindow_implementation::layout(), gui2::twindow::layout(), editor::map_context::map_context(), gui2::tcanvas::parse_cfg(), gui2::tgrid::place(), gui2::ttree_view_node::place(), gui2::tgrid::reduce_height(), gui2::tgrid::reduce_width(), wb::manager::set_planned_unit_map(), wb::manager::set_real_unit_map(), gui2::ttree_view_node::set_visible_rectangle(), gui2::twindow::show(), gui2::twindow::show_non_modal(), gui2::twindow::show_tooltip(), and gui2::tbuilder_grid::tbuilder_grid().
Definition at line 188 of file log.hpp.
Referenced by ai::typesafe_known_aspect< T >::add_facet(), ai::typesafe_known_aspect< T >::set(), gui2::show_error_message(), gui2::show_transient_error_message(), and ai::standard_aspect< config >::standard_aspect().