Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
c573d2b7
Commit
c573d2b7
authored
Oct 14, 2014
by
gabi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed default_formatter and formatters namespace
parent
481fdbcb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
52 deletions
+9
-52
formatter.h
include/c11log/formatter.h
+0
-42
logger.h
include/c11log/logger.h
+3
-2
pattern_formatter.h
include/c11log/pattern_formatter.h
+6
-8
No files found.
include/c11log/formatter.h
View file @
c573d2b7
...
...
@@ -16,52 +16,10 @@
namespace
c11log
{
namespace
formatters
{
class
formatter
{
public
:
virtual
void
format
(
details
::
log_msg
&
msg
)
=
0
;
};
class
default_formatter
:
public
formatter
{
public
:
// Format: [2013-12-29 01:04:42.900] [logger_name:Info] Message body
void
format
(
details
::
log_msg
&
msg
)
override
{
details
::
fast_oss
oss
;
_format_time
(
msg
,
oss
);
if
(
!
msg
.
logger_name
.
empty
())
oss
<<
" ["
<<
msg
.
logger_name
<<
':'
<<
c11log
::
level
::
to_str
(
msg
.
level
)
<<
"] "
;
else
oss
<<
" ["
<<
c11log
::
level
::
to_str
(
msg
.
level
)
<<
"] "
;
oss
<<
msg
.
raw
<<
details
::
os
::
eol
();
msg
.
formatted
=
oss
.
str
();
}
private
:
void
_format_time
(
const
details
::
log_msg
&
msg
,
std
::
ostream
&
output
);
};
}
//namespace formatter
}
//namespace c11log
// Format datetime like this: [2014-03-14 17:15:22]
inline
void
c11log
::
formatters
::
default_formatter
::
_format_time
(
const
details
::
log_msg
&
msg
,
std
::
ostream
&
output
)
{
output
.
fill
(
'0'
);
output
<<
'['
<<
msg
.
tm_time
.
tm_year
+
1900
<<
'-'
;
output
.
width
(
2
);
output
<<
msg
.
tm_time
.
tm_mon
+
1
<<
'-'
;
output
<<
msg
.
tm_time
.
tm_mday
<<
' '
;
output
<<
msg
.
tm_time
.
tm_hour
<<
':'
;
output
<<
msg
.
tm_time
.
tm_min
<<
':'
;
output
<<
msg
.
tm_time
.
tm_sec
<<
']'
;
}
include/c11log/logger.h
View file @
c573d2b7
...
...
@@ -14,6 +14,7 @@
#include "sinks/base_sink.h"
#include "common.h"
#include "pattern_formatter.h"
namespace
c11log
{
...
...
@@ -29,7 +30,7 @@ public:
using
sink_ptr
=
std
::
shared_ptr
<
sinks
::
isink
>
;
using
sinks_vector_t
=
std
::
vector
<
sink_ptr
>
;
using
sinks_init_list
=
std
::
initializer_list
<
sink_ptr
>
;
using
formatter_ptr
=
std
::
unique_ptr
<
formatter
s
::
formatter
>
;
using
formatter_ptr
=
std
::
unique_ptr
<
formatter
>
;
logger
(
const
std
::
string
&
name
,
sinks_init_list
,
formatter_ptr
=
nullptr
);
template
<
class
It
>
...
...
@@ -112,7 +113,7 @@ inline c11log::logger::logger(const std::string& name, sinks_init_list sinks_lis
//Seems that vs2013 doesn't support std::atomic member initialization yet
_level
=
level
::
INFO
;
if
(
!
_formatter
)
_formatter
=
std
::
make_unique
<
formatters
::
default_formatter
>
(
);
_formatter
=
std
::
make_unique
<
pattern_formatter
>
(
"%t"
);
}
...
...
include/c11log/pattern_formatter.h
View file @
c573d2b7
...
...
@@ -119,7 +119,7 @@ class e_appender :public pattern_appender
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
auto
duration
=
msg
.
time
.
time_since_epoch
();
auto
millis
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
duration
).
count
()
%
1000
;
int
millis
=
static_cast
<
int
>
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
duration
).
count
()
%
1000
)
;
oss
.
put_int
(
millis
,
3
);
}
};
...
...
@@ -166,8 +166,6 @@ private:
}
namespace
formatters
{
class
pattern_formatter
:
public
formatter
{
...
...
@@ -182,16 +180,16 @@ private:
void
compile_pattern
(
const
std
::
string
&
pattern
);
};
}
}
c11log
::
formatters
::
pattern_formatter
::
pattern_formatter
(
const
std
::
string
&
pattern
)
inline
c11log
::
pattern_formatter
::
pattern_formatter
(
const
std
::
string
&
pattern
)
{
compile_pattern
(
pattern
);
}
void
c11log
::
formatters
::
pattern_formatter
::
compile_pattern
(
const
std
::
string
&
pattern
)
inline
void
c11log
::
pattern_formatter
::
compile_pattern
(
const
std
::
string
&
pattern
)
{
auto
end
=
pattern
.
end
();
for
(
auto
it
=
pattern
.
begin
();
it
!=
end
;
++
it
)
...
...
@@ -211,7 +209,7 @@ void c11log::formatters::pattern_formatter::compile_pattern(const std::string& p
}
}
void
c11log
::
formatters
::
pattern_formatter
::
handle_flag
(
char
flag
)
inline
void
c11log
::
pattern_formatter
::
handle_flag
(
char
flag
)
{
switch
(
flag
)
{
...
...
@@ -273,7 +271,7 @@ void c11log::formatters::pattern_formatter::handle_flag(char flag)
}
void
c11log
::
formatters
::
pattern_formatter
::
format
(
details
::
log_msg
&
msg
)
inline
void
c11log
::
pattern_formatter
::
format
(
details
::
log_msg
&
msg
)
{
details
::
fast_oss
oss
;
for
(
auto
&
appender
:
_appenders
)
...
...
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