Skip to content

Commit

Permalink
[#272] Document usage of "set_level" for custom log categories.
Browse files Browse the repository at this point in the history
  • Loading branch information
korydraughn authored and alanking committed Aug 26, 2024
1 parent a5c3884 commit 83ce8aa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/developers/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ void example()
using logger = log::logger<my_category>;

try {
// Load the log level for our custom log category from server_config.json. If the
// log category isn't defined, the log level will be set to "log::level::info".
// Setting the log level is NOT thread-safe.
//
// Keep in mind that it is up to the developer to determine how the log level should
// be loaded. For example, instead of reading from server_config.json, the log level
// could be read from an environment variable.
//
// For developers implementing plugins with custom log categories, this step is very
// important as it allows plugins to react to changes to the log level in realtime.
// As a best practice, always set the log level before the plugin begins carrying
// out the real work.
logger::set_level(log::get_level_from_config(log::logger_config<my_category>::name));

// This message will be recorded.
logger::info("Hello, My Category!!!");

Expand Down

0 comments on commit 83ce8aa

Please sign in to comment.