Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
e7debaac
Commit
e7debaac
authored
Aug 05, 2016
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
astyle
parent
bdbe9086
Changes
11
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
798 additions
and
774 deletions
+798
-774
example/example.cpp
example/example.cpp
+13
-12
include/spdlog/details/async_log_helper.h
include/spdlog/details/async_log_helper.h
+16
-14
include/spdlog/details/async_logger_impl.h
include/spdlog/details/async_logger_impl.h
+12
-10
include/spdlog/details/file_helper.h
include/spdlog/details/file_helper.h
+1
-1
include/spdlog/details/logger_impl.h
include/spdlog/details/logger_impl.h
+103
-91
include/spdlog/details/os.h
include/spdlog/details/os.h
+23
-23
include/spdlog/details/pattern_formatter_impl.h
include/spdlog/details/pattern_formatter_impl.h
+569
-564
include/spdlog/details/registry.h
include/spdlog/details/registry.h
+9
-9
include/spdlog/details/spdlog_impl.h
include/spdlog/details/spdlog_impl.h
+1
-1
include/spdlog/logger.h
include/spdlog/logger.h
+10
-10
tests/errors.cpp
tests/errors.cpp
+41
-39
No files found.
example/example.cpp
View file @
e7debaac
...
...
@@ -134,7 +134,8 @@ void user_defined_example()
void
err_handler_example
()
{
//can be set globaly or per logger(logger->set_error_handler(..))
spdlog
::
set_error_handler
([](
const
std
::
string
&
msg
)
{
spdlog
::
set_error_handler
([](
const
std
::
string
&
msg
)
{
std
::
cerr
<<
"my err handler: "
<<
msg
<<
std
::
endl
;
});
spd
::
get
(
"console"
)
->
info
(
"some invalid message to trigger an error {}{}{}{}"
,
3
);
...
...
include/spdlog/details/async_log_helper.h
View file @
e7debaac
...
...
@@ -261,10 +261,12 @@ inline void spdlog::details::async_log_helper::worker_loop()
while
(
process_next_msg
(
last_pop
,
last_flush
));
if
(
_worker_teardown_cb
)
_worker_teardown_cb
();
}
catch
(
const
std
::
exception
&
ex
)
{
catch
(
const
std
::
exception
&
ex
)
{
_err_handler
(
ex
.
what
());
}
catch
(...)
{
catch
(...)
{
_err_handler
(
"Unknown exception"
);
}
}
...
...
include/spdlog/details/async_logger_impl.h
View file @
e7debaac
...
...
@@ -77,10 +77,12 @@ inline void spdlog::async_logger::_sink_it(details::log_msg& msg)
{
_async_log_helper
->
log
(
msg
);
}
catch
(
const
std
::
exception
&
ex
)
{
catch
(
const
std
::
exception
&
ex
)
{
_err_handler
(
ex
.
what
());
}
catch
(...)
{
catch
(...)
{
_err_handler
(
"Unknown exception"
);
}
}
include/spdlog/details/file_helper.h
View file @
e7debaac
include/spdlog/details/logger_impl.h
View file @
e7debaac
...
...
@@ -23,7 +23,10 @@ inline spdlog::logger::logger(const std::string& logger_name, const It& begin, c
_level
=
level
::
info
;
_flush_level
=
level
::
off
;
_last_err_time
=
0
;
_err_handler
=
[
this
](
const
std
::
string
&
msg
)
{
this
->
_default_err_handler
(
msg
);};
_err_handler
=
[
this
](
const
std
::
string
&
msg
)
{
this
->
_default_err_handler
(
msg
);
};
}
// ctor with sinks as init list
...
...
@@ -35,9 +38,9 @@ inline spdlog::logger::logger(const std::string& logger_name, sinks_init_list si
// ctor with single sink
inline
spdlog
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
spdlog
::
sink_ptr
single_sink
)
:
logger
(
logger_name
,
{
{
single_sink
})
})
{}
...
...
@@ -60,15 +63,18 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* fmt, const Ar
{
if
(
!
should_log
(
lvl
))
return
;
try
{
try
{
details
::
log_msg
log_msg
(
&
_name
,
lvl
);
log_msg
.
raw
.
write
(
fmt
,
args
...);
_sink_it
(
log_msg
);
}
catch
(
const
std
::
exception
&
ex
)
{
catch
(
const
std
::
exception
&
ex
)
{
_err_handler
(
ex
.
what
());
}
catch
(...)
{
catch
(...)
{
_err_handler
(
"Unknown exception"
);
}
}
...
...
@@ -77,15 +83,18 @@ template <typename... Args>
inline
void
spdlog
::
logger
::
log
(
level
::
level_enum
lvl
,
const
char
*
msg
)
{
if
(
!
should_log
(
lvl
))
return
;
try
{
try
{
details
::
log_msg
log_msg
(
&
_name
,
lvl
);
log_msg
.
raw
<<
msg
;
_sink_it
(
log_msg
);
}
catch
(
const
std
::
exception
&
ex
)
{
catch
(
const
std
::
exception
&
ex
)
{
_err_handler
(
ex
.
what
());
}
catch
(...)
{
catch
(...)
{
_err_handler
(
"Unknown exception"
);
}
...
...
@@ -95,15 +104,18 @@ template<typename T>
inline
void
spdlog
::
logger
::
log
(
level
::
level_enum
lvl
,
const
T
&
msg
)
{
if
(
!
should_log
(
lvl
))
return
;
try
{
try
{
details
::
log_msg
log_msg
(
&
_name
,
lvl
);
log_msg
.
raw
<<
msg
;
_sink_it
(
log_msg
);
}
catch
(
const
std
::
exception
&
ex
)
{
catch
(
const
std
::
exception
&
ex
)
{
_err_handler
(
ex
.
what
());
}
catch
(...)
{
catch
(...)
{
_err_handler
(
"Unknown exception"
);
}
}
...
...
include/spdlog/details/os.h
View file @
e7debaac
...
...
@@ -210,7 +210,7 @@ inline size_t filesize(FILE *f)
#else // unix
int
fd
=
fileno
(
f
);
//64 bits(but not in osx, where fstat64 is deprecated)
#if !defined(__FreeBSD__) && !defined(__APPLE__) && (defined(__x86_64__) || defined(__ppc64__))
#if !defined(__FreeBSD__) && !defined(__APPLE__) && (defined(__x86_64__) || defined(__ppc64__))
struct
stat64
st
;
if
(
fstat64
(
fd
,
&
st
)
==
0
)
return
st
.
st_size
;
...
...
include/spdlog/details/pattern_formatter_impl.h
View file @
e7debaac
This diff is collapsed.
Click to expand it.
include/spdlog/details/registry.h
View file @
e7debaac
include/spdlog/details/spdlog_impl.h
View file @
e7debaac
include/spdlog/logger.h
View file @
e7debaac
tests/errors.cpp
View file @
e7debaac
...
...
@@ -22,13 +22,14 @@ TEST_CASE("default_error_handler", "[errors]]")
}
struct
custom_ex
{};
struct
custom_ex
{};
TEST_CASE
(
"custom_error_handler"
,
"[errors]]"
)
{
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log.txt"
;
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple_file_sink_mt
>
(
"logger"
,
filename
,
true
);
logger
->
set_error_handler
([
=
](
const
std
::
string
&
msg
)
{
logger
->
set_error_handler
([
=
](
const
std
::
string
&
msg
)
{
throw
custom_ex
();
});
logger
->
info
(
"Good message #1"
);
...
...
@@ -45,7 +46,8 @@ TEST_CASE("async_error_handler", "[errors]]")
std
::
string
filename
=
"logs/simple_async_log.txt"
;
{
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple_file_sink_mt
>
(
"logger"
,
filename
,
true
);
logger
->
set_error_handler
([
=
](
const
std
::
string
&
msg
)
{
logger
->
set_error_handler
([
=
](
const
std
::
string
&
msg
)
{
std
::
ofstream
ofs
(
"logs/custom_err.txt"
);
if
(
!
ofs
)
throw
std
::
runtime_error
(
"Failed open logs/custom_err.txt"
);
ofs
<<
err_msg
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment