mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-28 17:19:34 +08:00
Wrap main
content in try block for exception safety.
This commit is contained in:
@@ -33,6 +33,7 @@ void mdc_example();
|
|||||||
#include "spdlog/fmt/ostr.h" // support for user defined types
|
#include "spdlog/fmt/ostr.h" // support for user defined types
|
||||||
|
|
||||||
int main(int, char *[]) {
|
int main(int, char *[]) {
|
||||||
|
try {
|
||||||
// Log levels can be loaded from argv/env using "SPDLOG_LEVEL"
|
// Log levels can be loaded from argv/env using "SPDLOG_LEVEL"
|
||||||
load_levels_example();
|
load_levels_example();
|
||||||
|
|
||||||
@@ -58,8 +59,8 @@ int main(int, char *[]) {
|
|||||||
spdlog::set_level(spdlog::level::info);
|
spdlog::set_level(spdlog::level::info);
|
||||||
|
|
||||||
// Backtrace support
|
// Backtrace support
|
||||||
// Loggers can store in a ring buffer all messages (including debug/trace) for later inspection.
|
// Loggers can store in a ring buffer all messages (including debug/trace) for later
|
||||||
// When needed, call dump_backtrace() to see what happened:
|
// inspection. When needed, call dump_backtrace() to see what happened:
|
||||||
spdlog::enable_backtrace(10); // create ring buffer with capacity of 10 messages
|
spdlog::enable_backtrace(10); // create ring buffer with capacity of 10 messages
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
spdlog::debug("Backtrace message {}", i); // not logged..
|
spdlog::debug("Backtrace message {}", i); // not logged..
|
||||||
@@ -67,7 +68,6 @@ int main(int, char *[]) {
|
|||||||
// e.g. if some error happened:
|
// e.g. if some error happened:
|
||||||
spdlog::dump_backtrace(); // log them now!
|
spdlog::dump_backtrace(); // log them now!
|
||||||
|
|
||||||
try {
|
|
||||||
stdout_logger_example();
|
stdout_logger_example();
|
||||||
basic_example();
|
basic_example();
|
||||||
rotating_example();
|
rotating_example();
|
||||||
|
Reference in New Issue
Block a user