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
41db9955
Commit
41db9955
authored
Oct 14, 2014
by
gabi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more code cleanup
parent
beca9138
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
103 additions
and
113 deletions
+103
-113
bench.cpp
example/bench.cpp
+7
-11
example.cpp
example/example.cpp
+1
-1
fast_istostr.h
include/c11log/details/fast_istostr.h
+1
-1
fast_oss.h
include/c11log/details/fast_oss.h
+6
-6
pattern_formatter.h
include/c11log/details/pattern_formatter.h
+34
-35
factory.h
include/c11log/factory.h
+8
-8
formatter.h
include/c11log/formatter.h
+0
-14
logger.h
include/c11log/logger.h
+39
-35
async_sink.h
include/c11log/sinks/async_sink.h
+1
-1
null_sink.h
include/c11log/sinks/null_sink.h
+6
-1
No files found.
example/bench.cpp
View file @
41db9955
...
@@ -17,27 +17,23 @@ using namespace utils;
...
@@ -17,27 +17,23 @@ using namespace utils;
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
const
unsigned
int
howmany
=
argc
<=
1
?
5
00000
:
atoi
(
argv
[
1
]);
const
unsigned
int
howmany
=
argc
<=
1
?
10
00000
:
atoi
(
argv
[
1
]);
std
::
string
pattern
=
"%Y:%m:%d %H:%M:%S.%e
[%n:%l] %t"
;
//std::string pattern = "%Y:%m:%d %H:%M:%S.%e --->
[%n:%l] %t";
auto
formatter1
=
std
::
unique_ptr
<
formatter
>
(
new
details
::
pattern_formatter
(
pattern
)
);
//auto formatter = std::make_shared<details::pattern_formatter>(pattern
);
logger
cout_logger
(
"bench"
,
std
::
make_shared
<
sinks
::
stderr_sink_mt
>
()
,
std
::
move
(
formatter1
)
);
logger
cout_logger
(
"bench"
,
{
std
::
make_shared
<
sinks
::
stderr_sink_mt
>
()
}
);
cout_logger
.
info
()
<<
"Hello logger
"
;
cout_logger
.
info
()
<<
"Hello logger
"
<<
std
::
setw
(
10
)
<<
std
::
setfill
(
'x'
)
<<
1234.55
;
auto
nullsink
=
std
::
make_shared
<
sinks
::
null_sink
<
details
::
null_mutex
>
>
();
auto
nullsink
=
std
::
make_shared
<
sinks
::
null_sink
_st
>
();
auto
rotating
=
std
::
make_shared
<
sinks
::
rotating_file_sink_mt
>
(
"myrotating"
,
"txt"
,
1024
*
1024
*
5
,
5
,
100
);
auto
rotating
=
std
::
make_shared
<
sinks
::
rotating_file_sink_mt
>
(
"myrotating"
,
"txt"
,
1024
*
1024
*
5
,
5
,
100
);
logger
my_logger
(
"my_logger"
,
{
nullsink
});
auto
formatter2
=
std
::
unique_ptr
<
formatter
>
(
new
details
::
pattern_formatter
(
pattern
));
logger
my_logger
(
"my_logger"
,
rotating
,
std
::
move
(
formatter2
));
auto
start
=
system_clock
::
now
();
auto
start
=
system_clock
::
now
();
for
(
unsigned
int
i
=
1
;
i
<=
howmany
;
++
i
)
for
(
unsigned
int
i
=
1
;
i
<=
howmany
;
++
i
)
my_logger
.
info
()
<<
"Hello logger: msg #"
<<
i
;
my_logger
.
info
()
<<
"Hello logger: msg #"
<<
i
;
auto
delta
=
system_clock
::
now
()
-
start
;
auto
delta
=
system_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
...
...
example/example.cpp
View file @
41db9955
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
#include "c11log/sinks/file_sinks.h"
#include "c11log/sinks/file_sinks.h"
using
namespace
std
;
using
namespace
std
;
int
main
(
int
,
char
*
[])
int
main
2
(
int
,
char
*
[])
{
{
auto
console
=
c11log
::
factory
::
stdout_logger
();
auto
console
=
c11log
::
factory
::
stdout_logger
();
...
...
include/c11log/details/fast_istostr.h
View file @
41db9955
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
//Fast to int to string
//Fast to int to string
//Source: http://stackoverflow.com/a/4351484/192001
//Source: http://stackoverflow.com/a/4351484/192001
//Modified version to pad zeros according to
min_size
//Modified version to pad zeros according to
padding arg
namespace
c11log
{
namespace
c11log
{
namespace
details
{
namespace
details
{
...
...
include/c11log/details/fast_oss.h
View file @
41db9955
...
@@ -105,21 +105,21 @@ public:
...
@@ -105,21 +105,21 @@ public:
_dev
.
clear
();
_dev
.
clear
();
}
}
// The following were added because they add significant boost to perfromance
//
// The following were added because they significantly boost to perfromance
//
void
putc
(
char
c
)
void
putc
(
char
c
)
{
{
_dev
.
sputc
(
c
);
_dev
.
sputc
(
c
);
this
->
width
(
4
);
}
}
// put int and pad with zeroes if smalled than min_width
// put int and pad with zeroes if smalled than min_width
void
put_int
(
int
n
,
int
min_width
)
void
put_int
(
int
n
,
int
padding
)
{
{
std
::
string
s
;
std
::
string
s
;
details
::
fast_itostr
(
n
,
s
,
min_width
);
details
::
fast_itostr
(
n
,
s
,
padding
);
_dev
.
sputn
(
s
.
data
(),
s
.
size
());
_dev
.
sputn
(
s
.
data
(),
s
.
size
());
//sprintf_s(buf, "%d", n);
//_dev.sputn(buf, width);
}
}
void
put_str
(
const
std
::
string
&
s
)
void
put_str
(
const
std
::
string
&
s
)
...
...
include/c11log/details/pattern_formatter.h
View file @
41db9955
...
@@ -8,19 +8,20 @@
...
@@ -8,19 +8,20 @@
#include "../formatter.h"
#include "../formatter.h"
#include "log_msg.h"
#include "log_msg.h"
#include "fast_oss.h"
#include "fast_oss.h"
#include "os.h"
namespace
c11log
namespace
c11log
{
{
namespace
details
{
namespace
details
{
class
pattern_
append
er
class
pattern_
compil
er
{
{
public
:
public
:
virtual
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
=
0
;
virtual
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
=
0
;
};
};
// log name appender
// log name appender
class
name_
appender
:
public
pattern_append
er
class
name_
compiler
:
public
pattern_compil
er
{
{
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -29,7 +30,7 @@ class name_appender :public pattern_appender
...
@@ -29,7 +30,7 @@ class name_appender :public pattern_appender
};
};
// log level appender
// log level appender
class
level_
appender
:
public
pattern_append
er
class
level_
compiler
:
public
pattern_compil
er
{
{
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -42,7 +43,7 @@ class level_appender :public pattern_appender
...
@@ -42,7 +43,7 @@ class level_appender :public pattern_appender
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// year - 4 digit
// year - 4 digit
class
Y_
appender
:
public
pattern_append
er
class
Y_
compiler
:
public
pattern_compil
er
{
{
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -51,7 +52,7 @@ class Y_appender :public pattern_appender
...
@@ -51,7 +52,7 @@ class Y_appender :public pattern_appender
};
};
// year - 2 digit
// year - 2 digit
class
y_
appender
:
public
pattern_append
er
class
y_
compiler
:
public
pattern_compil
er
{
{
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -59,7 +60,7 @@ class y_appender :public pattern_appender
...
@@ -59,7 +60,7 @@ class y_appender :public pattern_appender
}
}
};
};
// month 1-12
// month 1-12
class
m_
appender
:
public
pattern_append
er
class
m_
compiler
:
public
pattern_compil
er
{
{
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -67,9 +68,8 @@ class m_appender :public pattern_appender
...
@@ -67,9 +68,8 @@ class m_appender :public pattern_appender
}
}
};
};
// day of month 1-31
// day of month 1-31
class
d_
appender
:
public
pattern_append
er
class
d_
compiler
:
public
pattern_compil
er
{
{
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -78,7 +78,7 @@ class d_appender :public pattern_appender
...
@@ -78,7 +78,7 @@ class d_appender :public pattern_appender
};
};
// hours in 24 format 0-23
// hours in 24 format 0-23
class
H_
appender
:
public
pattern_append
er
class
H_
compiler
:
public
pattern_compil
er
{
{
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -87,7 +87,7 @@ class H_appender :public pattern_appender
...
@@ -87,7 +87,7 @@ class H_appender :public pattern_appender
};
};
// hours in 12 format 1-12
// hours in 12 format 1-12
class
I_
appender
:
public
pattern_append
er
class
I_
compiler
:
public
pattern_compil
er
{
{
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -96,7 +96,7 @@ class I_appender :public pattern_appender
...
@@ -96,7 +96,7 @@ class I_appender :public pattern_appender
};
};
// ninutes 0-59
// ninutes 0-59
class
M_
appender
:
public
pattern_append
er
class
M_
compiler
:
public
pattern_compil
er
{
{
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -105,7 +105,7 @@ class M_appender :public pattern_appender
...
@@ -105,7 +105,7 @@ class M_appender :public pattern_appender
};
};
// seconds 0-59
// seconds 0-59
class
S_
appender
:
public
pattern_append
er
class
S_
compiler
:
public
pattern_compil
er
{
{
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -114,7 +114,7 @@ class S_appender :public pattern_appender
...
@@ -114,7 +114,7 @@ class S_appender :public pattern_appender
};
};
// milliseconds
// milliseconds
class
e_
appender
:
public
pattern_append
er
class
e_
compiler
:
public
pattern_compil
er
{
{
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -125,7 +125,7 @@ class e_appender :public pattern_appender
...
@@ -125,7 +125,7 @@ class e_appender :public pattern_appender
};
};
class
t_
appender
:
public
pattern_append
er
class
t_
compiler
:
public
pattern_compil
er
{
{
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
msg
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -133,10 +133,10 @@ class t_appender :public pattern_appender
...
@@ -133,10 +133,10 @@ class t_appender :public pattern_appender
}
}
};
};
class
ch_
appender
:
public
pattern_append
er
class
ch_
compiler
:
public
pattern_compil
er
{
{
public
:
public
:
explicit
ch_
append
er
(
char
ch
)
:
_ch
(
ch
)
explicit
ch_
compil
er
(
char
ch
)
:
_ch
(
ch
)
{}
{}
void
append
(
const
details
::
log_msg
&
,
details
::
fast_oss
&
oss
)
override
void
append
(
const
details
::
log_msg
&
,
details
::
fast_oss
&
oss
)
override
{
{
...
@@ -147,10 +147,10 @@ private:
...
@@ -147,10 +147,10 @@ private:
};
};
class
str_
appender
:
public
pattern_append
er
class
str_
compiler
:
public
pattern_compil
er
{
{
public
:
public
:
str_
append
er
()
str_
compil
er
()
{}
{}
void
add_ch
(
char
ch
)
void
add_ch
(
char
ch
)
{
{
...
@@ -175,7 +175,7 @@ public:
...
@@ -175,7 +175,7 @@ public:
void
format
(
details
::
log_msg
&
msg
)
override
;
void
format
(
details
::
log_msg
&
msg
)
override
;
private
:
private
:
const
std
::
string
_pattern
;
const
std
::
string
_pattern
;
std
::
vector
<
std
::
unique_ptr
<
details
::
pattern_
appender
>>
_append
ers
;
std
::
vector
<
std
::
unique_ptr
<
details
::
pattern_
compiler
>>
_compil
ers
;
void
handle_flag
(
char
flag
);
void
handle_flag
(
char
flag
);
void
compile_pattern
(
const
std
::
string
&
pattern
);
void
compile_pattern
(
const
std
::
string
&
pattern
);
};
};
...
@@ -204,7 +204,7 @@ inline void c11log::details::pattern_formatter::compile_pattern(const std::strin
...
@@ -204,7 +204,7 @@ inline void c11log::details::pattern_formatter::compile_pattern(const std::strin
else
else
{
{
// chars not following the % sign should be displayed as is
// chars not following the % sign should be displayed as is
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
ch_append
er
(
*
it
)));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
ch_compil
er
(
*
it
)));
}
}
}
}
...
@@ -215,66 +215,65 @@ inline void c11log::details::pattern_formatter::handle_flag(char flag)
...
@@ -215,66 +215,65 @@ inline void c11log::details::pattern_formatter::handle_flag(char flag)
{
{
// logger name
// logger name
case
'n'
:
case
'n'
:
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
name_append
er
()));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
name_compil
er
()));
break
;
break
;
// message log level
// message log level
case
'l'
:
case
'l'
:
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
level_append
er
()));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
level_compil
er
()));
break
;
break
;
// message text
// message text
case
(
't'
)
:
case
(
't'
)
:
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
t_append
er
()));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
t_compil
er
()));
break
;
break
;
// year
// year
case
(
'Y'
)
:
case
(
'Y'
)
:
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
Y_append
er
()));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
Y_compil
er
()));
break
;
break
;
// year 2 digits
// year 2 digits
case
(
'y'
)
:
case
(
'y'
)
:
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
y_append
er
()));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
y_compil
er
()));
break
;
break
;
// month
// month
case
(
'm'
)
:
case
(
'm'
)
:
// minute
// minute
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
m_append
er
()));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
m_compil
er
()));
break
;
break
;
// day in month
// day in month
case
(
'd'
)
:
case
(
'd'
)
:
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
d_append
er
()));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
d_compil
er
()));
break
;
break
;
// hour (24)
// hour (24)
case
(
'H'
)
:
case
(
'H'
)
:
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
H_append
er
()));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
H_compil
er
()));
break
;
break
;
// hour (12)
// hour (12)
case
(
'I'
)
:
case
(
'I'
)
:
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
I_append
er
()));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
I_compil
er
()));
break
;
break
;
// minutes
// minutes
case
(
'M'
)
:
case
(
'M'
)
:
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
M_append
er
()));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
M_compil
er
()));
break
;
break
;
// seconds
// seconds
case
(
'S'
)
:
case
(
'S'
)
:
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
S_append
er
()));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
S_compil
er
()));
break
;
break
;
// milliseconds part
// milliseconds part
case
(
'e'
):
case
(
'e'
):
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
e_append
er
()));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
e_compil
er
()));
break
;
break
;
// % sign
// % sign
case
(
'%'
)
:
case
(
'%'
)
:
_
appenders
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_appender
>
(
new
details
::
ch_append
er
(
'%'
)));
_
compilers
.
push_back
(
std
::
unique_ptr
<
details
::
pattern_compiler
>
(
new
details
::
ch_compil
er
(
'%'
)));
break
;
break
;
}
}
}
}
inline
void
c11log
::
details
::
pattern_formatter
::
format
(
details
::
log_msg
&
msg
)
inline
void
c11log
::
details
::
pattern_formatter
::
format
(
details
::
log_msg
&
msg
)
{
{
details
::
fast_oss
oss
;
details
::
fast_oss
oss
;
for
(
auto
&
appender
:
_
append
ers
)
for
(
auto
&
appender
:
_
compil
ers
)
{
{
appender
->
append
(
msg
,
oss
);
appender
->
append
(
msg
,
oss
);
}
}
...
...
include/c11log/factory.h
View file @
41db9955
...
@@ -18,13 +18,13 @@ namespace factory
...
@@ -18,13 +18,13 @@ namespace factory
std
::
unique_ptr
<
logger
>
stdout_logger
(
const
std
::
string
&
name
=
""
)
std
::
unique_ptr
<
logger
>
stdout_logger
(
const
std
::
string
&
name
=
""
)
{
{
auto
sink
=
std
::
make_shared
<
sinks
::
stderr_sink_st
>
();
auto
sink
=
std
::
make_shared
<
sinks
::
stderr_sink_st
>
();
return
std
::
unique_ptr
<
logger
>
(
new
logger
(
name
,
sink
));
return
std
::
unique_ptr
<
logger
>
(
new
logger
(
name
,
{
sink
}
));
}
}
std
::
unique_ptr
<
logger
>
stdout_logger_mt
(
const
std
::
string
&
name
=
""
)
std
::
unique_ptr
<
logger
>
stdout_logger_mt
(
const
std
::
string
&
name
=
""
)
{
{
auto
sink
=
std
::
make_shared
<
sinks
::
stderr_sink_mt
>
();
auto
sink
=
std
::
make_shared
<
sinks
::
stderr_sink_mt
>
();
return
std
::
unique_ptr
<
logger
>
(
new
logger
(
name
,
sink
));
return
std
::
unique_ptr
<
logger
>
(
new
logger
(
name
,
{
sink
}
));
}
}
//
//
...
@@ -33,13 +33,13 @@ std::unique_ptr<logger> stdout_logger_mt(const std::string& name = "")
...
@@ -33,13 +33,13 @@ std::unique_ptr<logger> stdout_logger_mt(const std::string& name = "")
std
::
unique_ptr
<
logger
>
simple_file_logger
(
const
std
::
string
&
filename
,
const
std
::
string
&
logger_name
=
""
)
std
::
unique_ptr
<
logger
>
simple_file_logger
(
const
std
::
string
&
filename
,
const
std
::
string
&
logger_name
=
""
)
{
{
auto
fsink
=
std
::
make_shared
<
sinks
::
simple_file_sink_st
>
(
filename
);
auto
fsink
=
std
::
make_shared
<
sinks
::
simple_file_sink_st
>
(
filename
);
return
std
::
unique_ptr
<
logger
>
(
new
c11log
::
logger
(
logger_name
,
fsink
));
return
std
::
unique_ptr
<
logger
>
(
new
c11log
::
logger
(
logger_name
,
{
fsink
}
));
}
}
std
::
unique_ptr
<
logger
>
simple_file_logger_mt
(
const
std
::
string
&
filename
,
const
std
::
string
&
logger_name
=
""
)
std
::
unique_ptr
<
logger
>
simple_file_logger_mt
(
const
std
::
string
&
filename
,
const
std
::
string
&
logger_name
=
""
)
{
{
auto
fsink
=
std
::
make_shared
<
sinks
::
simple_file_sink_mt
>
(
filename
);
auto
fsink
=
std
::
make_shared
<
sinks
::
simple_file_sink_mt
>
(
filename
);
return
std
::
unique_ptr
<
logger
>
(
new
c11log
::
logger
(
logger_name
,
fsink
));
return
std
::
unique_ptr
<
logger
>
(
new
c11log
::
logger
(
logger_name
,
{
fsink
}
));
}
}
//
//
...
@@ -52,7 +52,7 @@ std::unique_ptr<logger> daily_file_logger(
...
@@ -52,7 +52,7 @@ std::unique_ptr<logger> daily_file_logger(
const
std
::
string
&
logger_name
=
""
)
const
std
::
string
&
logger_name
=
""
)
{
{
auto
fsink
=
std
::
make_shared
<
sinks
::
daily_file_sink_st
>
(
filename
,
extension
,
flush_every
);
auto
fsink
=
std
::
make_shared
<
sinks
::
daily_file_sink_st
>
(
filename
,
extension
,
flush_every
);
return
std
::
unique_ptr
<
logger
>
(
new
c11log
::
logger
(
logger_name
,
fsink
));
return
std
::
unique_ptr
<
logger
>
(
new
c11log
::
logger
(
logger_name
,
{
fsink
}
));
}
}
std
::
unique_ptr
<
logger
>
daily_file_logger_mt
(
std
::
unique_ptr
<
logger
>
daily_file_logger_mt
(
...
@@ -62,7 +62,7 @@ std::unique_ptr<logger> daily_file_logger_mt(
...
@@ -62,7 +62,7 @@ std::unique_ptr<logger> daily_file_logger_mt(
const
std
::
string
&
logger_name
=
""
)
const
std
::
string
&
logger_name
=
""
)
{
{
auto
fsink
=
std
::
make_shared
<
sinks
::
daily_file_sink_mt
>
(
filename
,
extension
,
flush_every
);
auto
fsink
=
std
::
make_shared
<
sinks
::
daily_file_sink_mt
>
(
filename
,
extension
,
flush_every
);
return
std
::
unique_ptr
<
logger
>
(
new
c11log
::
logger
(
logger_name
,
fsink
));
return
std
::
unique_ptr
<
logger
>
(
new
c11log
::
logger
(
logger_name
,
{
fsink
}
));
}
}
//
//
...
@@ -77,7 +77,7 @@ std::unique_ptr<logger> rotating_file_logger(
...
@@ -77,7 +77,7 @@ std::unique_ptr<logger> rotating_file_logger(
const
std
::
string
&
logger_name
=
""
)
const
std
::
string
&
logger_name
=
""
)
{
{
auto
fsink
=
std
::
make_shared
<
sinks
::
rotating_file_sink_st
>
(
filename
,
extension
,
max_size
,
max_files
,
flush_every
);
auto
fsink
=
std
::
make_shared
<
sinks
::
rotating_file_sink_st
>
(
filename
,
extension
,
max_size
,
max_files
,
flush_every
);
return
std
::
unique_ptr
<
logger
>
(
new
c11log
::
logger
(
logger_name
,
fsink
));
return
std
::
unique_ptr
<
logger
>
(
new
c11log
::
logger
(
logger_name
,
{
fsink
}
));
}
}
std
::
unique_ptr
<
logger
>
rotating_file_logger_mt
(
std
::
unique_ptr
<
logger
>
rotating_file_logger_mt
(
...
@@ -89,7 +89,7 @@ std::unique_ptr<logger> rotating_file_logger_mt(
...
@@ -89,7 +89,7 @@ std::unique_ptr<logger> rotating_file_logger_mt(
const
std
::
string
&
logger_name
=
""
)
const
std
::
string
&
logger_name
=
""
)
{
{
auto
fsink
=
std
::
make_shared
<
sinks
::
rotating_file_sink_mt
>
(
filename
,
extension
,
max_size
,
max_files
,
flush_every
);
auto
fsink
=
std
::
make_shared
<
sinks
::
rotating_file_sink_mt
>
(
filename
,
extension
,
max_size
,
max_files
,
flush_every
);
return
std
::
unique_ptr
<
logger
>
(
new
c11log
::
logger
(
logger_name
,
fsink
));
return
std
::
unique_ptr
<
logger
>
(
new
c11log
::
logger
(
logger_name
,
{
fsink
}
));
}
}
}
// ns factory
}
// ns factory
}
// ns c11log
}
// ns c11log
include/c11log/formatter.h
View file @
41db9955
#pragma once
#pragma once
#include <string>
#include <chrono>
#include <iomanip>
#include <thread>
#include <cstring>
#include <sstream>
#include "common.h"
#include "details/os.h"
#include "details/log_msg.h"
#include "details/log_msg.h"
#include "details/fast_oss.h"
namespace
c11log
namespace
c11log
{
{
...
...
include/c11log/logger.h
View file @
41db9955
...
@@ -29,15 +29,11 @@ class logger
...
@@ -29,15 +29,11 @@ class logger
{
{
public
:
public
:
using
sink_ptr
=
std
::
shared_ptr
<
sinks
::
sink
>
;
using
sink_ptr
=
std
::
shared_ptr
<
sinks
::
sink
>
;
using
sinks_vector_t
=
std
::
vector
<
sink_ptr
>
;
using
formatter_ptr
=
std
::
shared_ptr
<
formatter
>
;
using
sinks_init_list
=
std
::
initializer_list
<
sink_ptr
>
;
using
formatter_ptr
=
std
::
unique_ptr
<
formatter
>
;
logger
(
const
std
::
string
&
name
,
s
inks_init_list
,
formatter_pt
r
=
nullptr
);
logger
(
const
std
::
string
&
name
,
s
td
::
initializer_list
<
sink_ptr
>
,
formatter_ptr
formatte
r
=
nullptr
);
template
<
class
It
>
template
<
class
It
>
logger
(
const
std
::
string
&
name
,
It
begin
,
It
end
,
formatter_ptr
=
nullptr
);
logger
(
const
std
::
string
&
name
,
const
It
&
begin
,
const
It
&
end
);
logger
(
const
std
::
string
&
name
,
sink_ptr
,
formatter_ptr
=
nullptr
);
~
logger
()
=
default
;
logger
(
const
logger
&
)
=
delete
;
logger
(
const
logger
&
)
=
delete
;
logger
&
operator
=
(
const
logger
&
)
=
delete
;
logger
&
operator
=
(
const
logger
&
)
=
delete
;
...
@@ -48,6 +44,9 @@ public:
...
@@ -48,6 +44,9 @@ public:
const
std
::
string
&
name
()
const
;
const
std
::
string
&
name
()
const
;
bool
should_log
(
level
::
level_enum
)
const
;
bool
should_log
(
level
::
level_enum
)
const
;
void
formatter
(
formatter_ptr
);
formatter_ptr
formatter
()
const
;
template
<
typename
...
Args
>
details
::
line_logger
log
(
level
::
level_enum
lvl
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
log
(
level
::
level_enum
lvl
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
trace
(
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
trace
(
const
Args
&
...
args
);
...
@@ -57,20 +56,18 @@ public:
...
@@ -57,20 +56,18 @@ public:
template
<
typename
...
Args
>
details
::
line_logger
error
(
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
error
(
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
critical
(
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
critical
(
const
Args
&
...
args
);
private
:
private
:
friend
details
::
line_logger
;
friend
details
::
line_logger
;
std
::
string
_name
;
std
::
string
_name
;
formatter_ptr
_formatter
;
formatter_ptr
_formatter
;
s
inks_vector_t
_sinks
;
s
td
::
vector
<
sink_ptr
>
_sinks
;
std
::
atomic_int
_level
;
std
::
atomic_int
_level
;
void
_variadic_log
(
details
::
line_logger
&
l
);
void
_variadic_log
(
details
::
line_logger
&
l
);
template
<
typename
First
,
typename
...
Rest
>
template
<
typename
First
,
typename
...
Rest
>
void
_variadic_log
(
details
::
line_logger
&
l
,
const
First
&
first
,
const
Rest
&
...
rest
);
void
_variadic_log
(
details
::
line_logger
&
l
,
const
First
&
first
,
const
Rest
&
...
rest
);
void
_log_msg
(
details
::
log_msg
&
msg
);
void
_log_msg
(
details
::
log_msg
&
msg
);
formatter_ptr
_default_formatter
();
const
char
*
_default_pattern
=
"[%Y:%m:%d %H:%M:%S.%e] [%n:%l] %t"
;
};
};
...
@@ -98,30 +95,24 @@ private:
...
@@ -98,30 +95,24 @@ private:
#include "details/line_logger.h"
#include "details/line_logger.h"
inline
c11log
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
s
inks_init_list
sinks_list
,
formatter_ptr
f
)
:
inline
c11log
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
s
td
::
initializer_list
<
sink_ptr
>
sinks_list
,
formatter_ptr
formatter
)
:
_name
(
logger_name
),
_name
(
logger_name
),
_formatter
(
std
::
move
(
f
)
),
_formatter
(
formatter
),
_sinks
(
sinks_list
)
_sinks
(
sinks_list
)
{
{
//Seems that vs2013 doesn't support std::atomic member initialization yet
if
(
!
formatter
)
//default formatter
_formatter
=
std
::
make_shared
<
details
::
pattern_formatter
>
(
_default_pattern
);
//Seems that vs2013 doesn't support atomic member initialization yet
_level
=
level
::
INFO
;
_level
=
level
::
INFO
;
if
(
!
_formatter
)
_formatter
=
formatter_ptr
(
new
details
::
pattern_formatter
(
"%t"
));
}
}
template
<
class
It
>
template
<
class
It
>
inline
c11log
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
It
begin
,
It
end
,
formatter_ptr
f
)
:
inline
c11log
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
const
It
&
begin
,
const
It
&
end
)
:
_name
(
logger_name
),
_name
(
logger_name
),
_formatter
(
std
::
move
(
f
)),
_sinks
(
begin
,
end
)
_sinks
(
begin
,
end
)
{
{}
}
inline
c11log
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
sink_ptr
sink
,
formatter_ptr
f
)
:
logger
(
logger_name
,
{
sink
},
std
::
move
(
f
))
{}
template
<
typename
...
Args
>
template
<
typename
...
Args
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
log
(
level
::
level_enum
lvl
,
const
Args
&
...
args
)
{
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
log
(
level
::
level_enum
lvl
,
const
Args
&
...
args
)
{
...
@@ -130,35 +121,36 @@ inline c11log::details::line_logger c11log::logger::log(level::level_enum lvl, c
...
@@ -130,35 +121,36 @@ inline c11log::details::line_logger c11log::logger::log(level::level_enum lvl, c
return
l
;
return
l
;
}
}
template
<
typename
...
Args
>
template
<
typename
...
Args
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
trace
(
const
Args
&
...
args
)
{
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
trace
(
const
Args
&
...
args
)
{
return
log
(
level
::
TRACE
,
args
...);
return
log
(
level
::
TRACE
,
args
...);
}
}
template
<
typename
...
Args
>
template
<
typename
...
Args
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
debug
(
const
Args
&
...
args
)
{
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
debug
(
const
Args
&
...
args
)
{
return
log
(
level
::
DEBUG
,
args
...);
return
log
(
level
::
DEBUG
,
args
...);
}
}
template
<
typename
...
Args
>
template
<
typename
...
Args
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
info
(
const
Args
&
...
args
)
{
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
info
(
const
Args
&
...
args
)
{
return
log
(
level
::
INFO
,
args
...);
return
log
(
level
::
INFO
,
args
...);
}
}
template
<
typename
...
Args
>
template
<
typename
...
Args
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
warn
(
const
Args
&
...
args
)
{
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
warn
(
const
Args
&
...
args
)
{
return
log
(
level
::
WARNING
,
args
...);
return
log
(
level
::
WARNING
,
args
...);
}
}
template
<
typename
...
Args
>
template
<
typename
...
Args
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
critical
(
const
Args
&
...
args
)
{
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
critical
(
const
Args
&
...
args
)
{
return
log
(
level
::
CRITICAL
,
args
...);
return
log
(
level
::
CRITICAL
,
args
...);
}
}
inline
const
std
::
string
&
c11log
::
logger
::
name
()
const
inline
const
std
::
string
&
c11log
::
logger
::
name
()
const
{
{
return
_name
;
return
_name
;
...
@@ -180,6 +172,18 @@ inline bool c11log::logger::should_log(c11log::level::level_enum msg_level) cons
...
@@ -180,6 +172,18 @@ inline bool c11log::logger::should_log(c11log::level::level_enum msg_level) cons
}
}
inline
void
c11log
::
logger
::
formatter
(
formatter_ptr
formatter
)
{
_formatter
=
formatter
;
}
inline
c11log
::
logger
::
formatter_ptr
c11log
::
logger
::
formatter
()
const
{
return
_formatter
;
}
inline
void
c11log
::
logger
::
_variadic_log
(
c11log
::
details
::
line_logger
&
)
{}
inline
void
c11log
::
logger
::
_variadic_log
(
c11log
::
details
::
line_logger
&
)
{}
template
<
typename
First
,
typename
...
Rest
>
template
<
typename
First
,
typename
...
Rest
>
...
...
include/c11log/sinks/async_sink.h
View file @
41db9955
...
@@ -39,7 +39,7 @@ protected:
...
@@ -39,7 +39,7 @@ protected:
void
_thread_loop
();
void
_thread_loop
();
private
:
private
:
c11log
::
logger
::
sinks_vector_t
_sinks
;
std
::
vector
<
std
::
shared_ptr
<
sink
>>
_sinks
;
std
::
atomic
<
bool
>
_active
;
std
::
atomic
<
bool
>
_active
;
q_type
_q
;
q_type
_q
;
std
::
thread
_back_thread
;
std
::
thread
_back_thread
;
...
...
include/c11log/sinks/null_sink.h
View file @
41db9955
#pragma once
#pragma once
#include <mutex>
#include "base_sink.h"
#include "base_sink.h"
#include "../details/null_mutex.h"
namespace
c11log
{
namespace
c11log
{
namespace
sinks
{
namespace
sinks
{
...
@@ -13,6 +15,9 @@ protected:
...
@@ -13,6 +15,9 @@ protected:
{}
{}
};
};
typedef
null_sink
<
details
::
null_mutex
>
null_sink_st
;
typedef
null_sink
<
std
::
mutex
>
null_sink_mt
;
}
}
}
}
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