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
b49b0867
Commit
b49b0867
authored
Oct 10, 2014
by
gabi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some syntactic improvements
parent
ae2426e0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
49 deletions
+27
-49
flush_helper.h
include/c11log/details/flush_helper.h
+3
-0
line_logger.h
include/c11log/details/line_logger.h
+2
-3
logger.h
include/c11log/logger.h
+19
-27
base_sink.h
include/c11log/sinks/base_sink.h
+3
-17
isink.h
include/c11log/sinks/isink.h
+0
-2
No files found.
include/c11log/details/flush_helper.h
View file @
b49b0867
#pragma once
// Flush to file every X writes..
// If X is zero than never flush..
namespace
c11log
{
...
...
@@ -13,6 +14,8 @@ public:
_flush_every
(
flush_every
),
_flush_countdown
(
flush_every
)
{};
file_flush_helper
(
const
file_flush_helper
&
)
=
delete
;
void
write
(
const
std
::
string
&
msg
,
std
::
ofstream
&
ofs
)
{
ofs
.
write
(
msg
.
data
(),
msg
.
size
());
...
...
include/c11log/details/line_logger.h
View file @
b49b0867
...
...
@@ -11,10 +11,9 @@
namespace
c11log
{
//class logger;
namespace
details
{
class
line_logger
{
public
:
...
...
@@ -45,7 +44,7 @@ public:
{
if
(
_enabled
)
{
_log_msg
.
logger_name
=
_callback_logger
->
get_
name
();
_log_msg
.
logger_name
=
_callback_logger
->
name
();
_log_msg
.
time
=
log_clock
::
now
();
_log_msg
.
raw
=
_oss
.
str
();
_callback_logger
->
_log_it
(
_log_msg
);
...
...
include/c11log/logger.h
View file @
b49b0867
#pragma once
// Thread safe logger
// Has log level and vector sinks which do the actual logging
// Has name, log level, vector of std::shared sink pointers and formatter
// Upon each log write the logger:
// 1. Checks if its log level is enough to log the message
// 2. Format the message using the formatter function
// 3. Pass the formatted message to it sinks to performa the actual logging
#include<vector>
#include<memory>
#include<atomic>
...
...
@@ -10,44 +15,33 @@
#include "sinks/base_sink.h"
#include "common.h"
//Thread safe, fast logger.
//All initialization is done in ctor only, so we get away lot of locking
namespace
c11log
{
namespace
details
{
class
line_logger
;
template
<
std
::
size_t
>
class
fast_buf
;
}
class
logger
{
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
<
c11log
::
formatters
::
formatter
>
;
logger
(
const
std
::
string
&
name
,
sinks_init_list
,
formatter_ptr
=
nullptr
);
logger
(
const
std
::
string
&
name
,
sink_ptr
,
formatter_ptr
=
nullptr
);
~
logger
()
=
default
;
//Non copybale in anyway
logger
(
const
logger
&
)
=
delete
;
logger
(
logger
&&
)
=
delete
;
logger
&
operator
=
(
const
logger
&
)
=
delete
;
logger
&
operator
=
(
logger
&&
)
=
delete
;
~
logger
()
=
default
;
void
set_min_level
(
c11log
::
level
::
level_enum
);
c11log
::
level
::
level_enum
get_level
()
const
;
const
std
::
string
&
get_name
()
const
;
void
level
(
c11log
::
level
::
level_enum
);
c11log
::
level
::
level_enum
level
()
const
;
const
std
::
string
&
name
()
const
;
bool
should_log
(
c11log
::
level
::
level_enum
)
const
;
template
<
typename
T
>
details
::
line_logger
trace
(
const
T
&
);
...
...
@@ -73,7 +67,7 @@ private:
std
::
string
_logger_name
;
formatter_ptr
_formatter
;
sinks_vector_t
_sinks
;
std
::
atomic_int
_
min_
level
;
std
::
atomic_int
_level
;
void
_log_it
(
details
::
log_msg
&
msg
);
};
...
...
@@ -84,7 +78,6 @@ private:
}
//
// Logger implementation
//
...
...
@@ -109,7 +102,7 @@ inline c11log::logger::logger(const std::string& name, sinks_init_list sinks_lis
_sinks
(
sinks_list
)
{
//Seems that vs2013 doesn't support std::atomic member initialization yet
_
min_
level
=
level
::
INFO
;
_level
=
level
::
INFO
;
if
(
!
_formatter
)
_formatter
=
std
::
make_unique
<
formatters
::
default_formatter
>
();
...
...
@@ -120,7 +113,6 @@ inline c11log::logger::logger(const std::string& name, sink_ptr sink, formatter_
logger
(
name
,
{
sink
},
std
::
move
(
f
))
{}
template
<
typename
T
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
trace
(
const
T
&
msg
)
{
...
...
@@ -201,24 +193,24 @@ inline c11log::details::line_logger c11log::logger::fatal()
}
inline
const
std
::
string
&
c11log
::
logger
::
get_
name
()
const
inline
const
std
::
string
&
c11log
::
logger
::
name
()
const
{
return
_logger_name
;
}
inline
void
c11log
::
logger
::
set_min_
level
(
c11log
::
level
::
level_enum
level
)
inline
void
c11log
::
logger
::
level
(
c11log
::
level
::
level_enum
level
)
{
_
min_
level
.
store
(
level
);
_level
.
store
(
level
);
}
inline
c11log
::
level
::
level_enum
c11log
::
logger
::
get_
level
()
const
inline
c11log
::
level
::
level_enum
c11log
::
logger
::
level
()
const
{
return
static_cast
<
c11log
::
level
::
level_enum
>
(
_
min_
level
.
load
());
return
static_cast
<
c11log
::
level
::
level_enum
>
(
_level
.
load
());
}
inline
bool
c11log
::
logger
::
should_log
(
c11log
::
level
::
level_enum
level
)
const
{
return
level
>=
_
min_
level
.
load
();
return
level
>=
_level
.
load
();
}
inline
void
c11log
::
logger
::
_log_it
(
details
::
log_msg
&
msg
)
...
...
include/c11log/sinks/base_sink.h
View file @
b49b0867
...
...
@@ -17,7 +17,7 @@ template<class Mutex>
class
base_sink
:
public
isink
{
public
:
base_sink
()
:
_mutex
()
,
_enabled
(
true
)
{}
base_sink
()
:
_mutex
()
{}
virtual
~
base_sink
()
=
default
;
base_sink
(
const
base_sink
&
)
=
delete
;
...
...
@@ -25,28 +25,14 @@ public:
void
log
(
const
details
::
log_msg
&
msg
)
override
{
if
(
_enabled
)
{
std
::
lock_guard
<
Mutex
>
lock
(
_mutex
);
_sink_it
(
msg
);
}
std
::
lock_guard
<
Mutex
>
lock
(
_mutex
);
_sink_it
(
msg
);
};
void
enable
(
bool
enabled
)
override
{
_enabled
=
enabled
;
}
bool
is_enabled
()
override
{
return
_enabled
.
load
();
}
protected
:
virtual
void
_sink_it
(
const
details
::
log_msg
&
msg
)
=
0
;
Mutex
_mutex
;
std
::
atomic
<
bool
>
_enabled
;
};
}
}
include/c11log/sinks/isink.h
View file @
b49b0867
...
...
@@ -10,8 +10,6 @@ class isink
{
public
:
virtual
void
log
(
const
details
::
log_msg
&
msg
)
=
0
;
virtual
void
enable
(
bool
enabled
)
=
0
;
virtual
bool
is_enabled
()
=
0
;
};
}
}
...
...
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