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
c9dd1169
Commit
c9dd1169
authored
Mar 07, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
returned fast_oss with optimizations
parent
63812d7a
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
117 additions
and
85 deletions
+117
-85
astyle.sh
astyle.sh
+2
-1
example/example.cpp
example/example.cpp
+1
-1
example/utils.h
example/utils.h
+2
-1
include/c11log/common_types.h
include/c11log/common_types.h
+4
-2
include/c11log/details/blocking_queue.h
include/c11log/details/blocking_queue.h
+6
-3
include/c11log/details/factory.h
include/c11log/details/factory.h
+6
-3
include/c11log/details/fast_oss.h
include/c11log/details/fast_oss.h
+16
-21
include/c11log/details/flush_helper.h
include/c11log/details/flush_helper.h
+6
-3
include/c11log/details/line_logger.h
include/c11log/details/line_logger.h
+11
-6
include/c11log/details/os.h
include/c11log/details/os.h
+6
-3
include/c11log/formatter.h
include/c11log/formatter.h
+9
-6
include/c11log/logger.h
include/c11log/logger.h
+7
-9
include/c11log/sinks/async_sink.h
include/c11log/sinks/async_sink.h
+6
-3
include/c11log/sinks/base_sink.h
include/c11log/sinks/base_sink.h
+8
-4
include/c11log/sinks/file_sinks.h
include/c11log/sinks/file_sinks.h
+17
-12
include/c11log/sinks/stdout_sinks.h
include/c11log/sinks/stdout_sinks.h
+10
-7
No files found.
astyle.sh
View file @
c9dd1169
#!/bin/bash
find
.
-name
"*
\.
h"
-o
-name
"*
\.
cpp"
|xargs astyle
--style
=
stroustrup
find
.
-name
"*
\.
h"
-o
-name
"*
\.
cpp"
|xargs astyle
-A8
example/example.cpp
View file @
c9dd1169
...
...
@@ -58,8 +58,8 @@ int main(int argc, char* argv[])
auto
&
my_logger
=
get_logger
(
"example"
);
auto
null_sink
=
std
::
make_shared
<
sinks
::
null_sink
>
();
//auto async = std::make_shared<sinks::async_sink>(1000);
//async->add_sink(fsink);
my_logger
.
add_sink
(
fsink
);
//my_logger.add_sink(null_sink);
auto
start
=
system_clock
::
now
();
...
...
example/utils.h
View file @
c9dd1169
...
...
@@ -7,7 +7,8 @@
#include <iomanip>
#include <locale>
namespace
utils
{
namespace
utils
{
template
<
typename
T
>
std
::
string
format
(
const
T
&
value
)
...
...
include/c11log/common_types.h
View file @
c9dd1169
...
...
@@ -2,11 +2,13 @@
#include <chrono>
namespace
c11log
{
namespace
c11log
{
typedef
std
::
chrono
::
system_clock
log_clock
;
namespace
level
{
namespace
level
{
typedef
enum
{
DEBUG
,
INFO
,
...
...
include/c11log/details/blocking_queue.h
View file @
c9dd1169
...
...
@@ -10,11 +10,14 @@
#include <mutex>
#include <condition_variable>
namespace
c11log
{
namespace
details
{
namespace
c11log
{
namespace
details
{
template
<
typename
T
>
class
blocking_queue
{
class
blocking_queue
{
public:
using
queue_t
=
std
::
queue
<
T
>
;
using
size_type
=
typename
queue_t
::
size_type
;
...
...
include/c11log/details/factory.h
View file @
c9dd1169
...
...
@@ -5,10 +5,13 @@
#include <memory>
#include <mutex>
namespace
c11log
{
namespace
c11log
{
class
logger
;
namespace
details
{
class
factory
{
namespace
details
{
class
factory
{
public:
typedef
std
::
shared_ptr
<
c11log
::
logger
>
logger_ptr
;
typedef
std
::
unordered_map
<
std
::
string
,
logger_ptr
>
logger_map
;
...
...
include/c11log/details/fast_oss.h
View file @
c9dd1169
#pragma once
// Fast ostringstream like supprt which return its string by ref and nothing more
#include<streambuf>
#include<string>
namespace
c11log
{
namespace
details
{
class
str_devicebuf
:
public
std
::
streambuf
{
namespace
c11log
{
namespace
details
{
class
str_devicebuf
:
public
std
::
streambuf
{
public:
str_devicebuf
()
=
default
;
~
str_devicebuf
()
=
default
;
str_devicebuf
(
const
str_devicebuf
&
other
)
:
std
::
streambuf
(),
_str
(
other
.
_str
)
{}
str_devicebuf
(
str_devicebuf
&&
other
)
:
std
::
streambuf
(),
_str
(
std
::
move
(
other
.
_str
))
{
other
.
_str
.
clear
();
}
str_devicebuf
(
const
str_devicebuf
&
other
)
=
delete
;
str_devicebuf
(
str_devicebuf
&&
other
)
=
delete
;
str_devicebuf
&
operator
=
(
const
str_devicebuf
&
)
=
delete
;
str_devicebuf
&
operator
=
(
str_devicebuf
&&
)
=
delete
;
const
std
::
string
&
str_ref
()
const
{
return
_str
;
std
::
ostringstream
oss
;
}
void
clear
()
{
...
...
@@ -47,29 +49,22 @@ private:
std
::
string
_str
;
};
class
fast_oss
:
public
std
::
ostream
{
class
fast_oss
:
public
std
::
ostream
{
public:
fast_oss
()
:
std
::
ostream
(
&
_dev
)
{}
~
fast_oss
()
=
default
;
fast_oss
(
const
fast_oss
&
other
)
:
std
::
basic_ios
<
char
>
(),
std
::
ostream
(
&
_dev
),
_dev
(
other
.
_dev
)
{}
fast_oss
(
fast_oss
&&
other
)
:
std
::
basic_ios
<
char
>
(),
std
::
ostream
(
&
_dev
),
_dev
(
std
::
move
(
other
.
_dev
))
{}
fast_oss
(
const
fast_oss
&
other
)
=
delete
;
fast_oss
(
fast_oss
&&
other
)
=
delete
;
fast_oss
&
operator
=
(
const
fast_oss
&
other
)
=
delete
;
const
std
::
string
&
str_ref
()
const
{
return
_dev
.
str_ref
();
}
const
std
::
string
str
()
const
{
return
_dev
.
str_ref
();
}
void
clear
()
{
_dev
.
clear
();
}
private:
str_devicebuf
_dev
;
};
...
...
include/c11log/details/flush_helper.h
View file @
c9dd1169
...
...
@@ -3,9 +3,12 @@
#include <iostream>
// Flush to file every X writes..
namespace
c11log
{
namespace
details
{
class
file_flush_helper
{
namespace
c11log
{
namespace
details
{
class
file_flush_helper
{
public:
explicit
file_flush_helper
(
const
std
::
chrono
::
milliseconds
&
flush_every
)
:
_flush_every
(
flush_every
),
_last_flush
()
{};
...
...
include/c11log/details/line_logger.h
View file @
c9dd1169
...
...
@@ -2,13 +2,17 @@
#include "../common_types.h"
#include "../logger.h"
#include "fast_oss.h"
#include <iostream>
namespace
c11log
{
namespace
c11log
{
class
logger
;
namespace
details
{
namespace
details
{
class
line_logger
{
class
line_logger
{
public:
line_logger
(
logger
*
callback_logger
,
level
::
level_enum
msg_level
,
bool
enabled
)
:
_callback_logger
(
callback_logger
),
...
...
@@ -25,7 +29,7 @@ public:
line_logger
(
line_logger
&&
other
)
:
_callback_logger
(
other
.
_callback_logger
),
_oss
(
std
::
move
(
other
.
_oss
)
),
_oss
(),
_level
(
other
.
_level
)
{
};
...
...
@@ -36,7 +40,7 @@ public:
~
line_logger
()
{
if
(
_enabled
)
{
_oss
<<
'\n'
;
_callback_logger
->
_log_it
(
_oss
.
str
(),
_level
);
_callback_logger
->
_log_it
(
_oss
.
str
_ref
(),
_level
);
}
}
...
...
@@ -50,7 +54,8 @@ public:
private:
logger
*
_callback_logger
;
std
::
ostringstream
_oss
;
//std::ostringstream _oss;
details
::
fast_oss
_oss
;
level
::
level_enum
_level
;
bool
_enabled
;
...
...
include/c11log/details/os.h
View file @
c9dd1169
...
...
@@ -3,9 +3,12 @@
#include<cstdio>
#include<ctime>
namespace
c11log
{
namespace
details
{
namespace
os
{
namespace
c11log
{
namespace
details
{
namespace
os
{
inline
std
::
tm
localtime
(
const
std
::
time_t
&
time_tt
)
{
...
...
include/c11log/formatter.h
View file @
c9dd1169
...
...
@@ -10,15 +10,18 @@
#include "common_types.h"
#include "details/os.h"
namespace
c11log
{
namespace
formatters
{
namespace
c11log
{
namespace
formatters
{
typedef
std
::
function
<
std
::
string
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
,
level
::
level_enum
,
const
c11log
::
log_clock
::
time_point
&
)
>
format_fn
;
std
::
string
to_hex
(
const
unsigned
char
*
buf
,
std
::
size_t
size
);
class
formatter
{
class
formatter
{
public:
formatter
()
{}
virtual
~
formatter
()
{}
...
...
@@ -26,7 +29,8 @@ public:
};
class
default_formatter
:
public
formatter
{
class
default_formatter
:
public
formatter
{
public:
// Format: [2013-12-29 01:04:42.900] [logger_name:Info] Message body
void
format_header
(
const
std
::
string
&
logger_name
,
level
::
level_enum
level
,
const
log_clock
::
time_point
&
tp
,
std
::
ostream
&
dest
)
override
{
...
...
@@ -55,8 +59,7 @@ inline void c11log::formatters::default_formatter::_format_time(const log_clock:
auto
tm_now
=
details
::
os
::
localtime
(
log_clock
::
to_time_t
(
tp
));
using
namespace
c11log
::
details
::
os
;
if
(
last_tm
!=
tm_now
)
{
if
(
last_tm
!=
tm_now
)
{
#ifdef _MSC_VER
::
sprintf_s
#else
...
...
include/c11log/logger.h
View file @
c9dd1169
...
...
@@ -12,15 +12,18 @@
#include "sinks/base_sink.h"
#include "details/factory.h"
namespace
c11log
{
namespace
c11log
{
namespace
details
{
namespace
details
{
class
line_logger
;
}
class
logger
{
class
logger
{
public:
typedef
std
::
shared_ptr
<
sinks
::
base_sink
>
sink_ptr_t
;
...
...
@@ -30,8 +33,7 @@ public:
_logger_name
(
name
),
_formatter
(
new
formatters
::
default_formatter
()),
_sinks
(),
_mutex
()
{
_mutex
()
{
//Seems that vs2013 doesnt support atomic member initialization in ctor, so its done here
_atomic_level
=
level
::
INFO
;
}
...
...
@@ -72,13 +74,9 @@ private:
logger
&
get_logger
(
const
std
::
string
&
name
);
}
//
// Logger inline impl
//
...
...
include/c11log/sinks/async_sink.h
View file @
c9dd1169
...
...
@@ -8,10 +8,13 @@
#include "../logger.h"
#include "../details/blocking_queue.h"
namespace
c11log
{
namespace
sinks
{
namespace
c11log
{
namespace
sinks
{
class
async_sink
:
public
base_sink
{
class
async_sink
:
public
base_sink
{
public:
using
size_type
=
c11log
::
details
::
blocking_queue
<
std
::
string
>::
size_type
;
...
...
include/c11log/sinks/base_sink.h
View file @
c9dd1169
...
...
@@ -6,9 +6,12 @@
#include "../formatter.h"
#include "../common_types.h"
namespace
c11log
{
namespace
sinks
{
class
base_sink
{
namespace
c11log
{
namespace
sinks
{
class
base_sink
{
public:
base_sink
()
=
default
;
base_sink
(
level
::
level_enum
l
)
:
_level
(
l
)
{
...
...
@@ -33,7 +36,8 @@ protected:
std
::
atomic
<
int
>
_level
{
level
::
INFO
};
};
class
null_sink
:
public
base_sink
{
class
null_sink
:
public
base_sink
{
protected:
void
_sink_it
(
const
std
::
string
&
)
override
{
}
...
...
include/c11log/sinks/file_sinks.h
View file @
c9dd1169
...
...
@@ -6,13 +6,16 @@
#include "base_sink.h"
#include "../details/flush_helper.h"
namespace
c11log
{
namespace
sinks
{
namespace
c11log
{
namespace
sinks
{
/*
* Trivial file sink with single file as target
*/
class
simple_file_sink
:
public
base_sink
{
class
simple_file_sink
:
public
base_sink
{
public:
explicit
simple_file_sink
(
const
std
::
string
&
filename
,
const
std
::
string
&
extension
,
...
...
@@ -36,7 +39,8 @@ private:
/*
* Thread safe, size limited file sink
*/
class
rotating_file_sink
:
public
base_sink
{
class
rotating_file_sink
:
public
base_sink
{
public:
rotating_file_sink
(
const
std
::
string
&
base_filename
,
const
std
::
string
&
extension
,
size_t
max_size
,
size_t
max_files
,
...
...
@@ -104,7 +108,8 @@ private:
/*
* Thread safe file sink that closes the log file at midnight and opens new one
*/
class
daily_file_sink
:
public
base_sink
{
class
daily_file_sink
:
public
base_sink
{
public:
explicit
daily_file_sink
(
const
std
::
string
&
base_filename
,
const
std
::
string
&
extension
,
...
...
@@ -140,14 +145,14 @@ private:
return
system_clock
::
time_point
(
midnight
+
hours
(
24
));
}
//Create filename for the form basename.YYYY-MM-DD.extension
//Create filename for the form basename.YYYY-MM-DD.extension
static
std
::
string
_calc_filename
(
const
std
::
string
&
basename
,
const
std
::
string
&
extension
)
{
std
::
tm
tm
=
c11log
::
details
::
os
::
localtime
();
std
::
ostringstream
oss
;
oss
<<
basename
<<
'.'
;
oss
<<
tm
.
tm_year
+
1900
<<
'-'
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tm
.
tm_mon
+
1
<<
'-'
<<
tm
.
tm_mday
;
oss
<<
'.'
<<
extension
;
return
oss
.
str
();
std
::
tm
tm
=
c11log
::
details
::
os
::
localtime
();
std
::
ostringstream
oss
;
oss
<<
basename
<<
'.'
;
oss
<<
tm
.
tm_year
+
1900
<<
'-'
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tm
.
tm_mon
+
1
<<
'-'
<<
tm
.
tm_mday
;
oss
<<
'.'
<<
extension
;
return
oss
.
str
();
}
std
::
string
_base_filename
;
...
...
include/c11log/sinks/stdout_sinks.h
View file @
c9dd1169
...
...
@@ -6,23 +6,26 @@
#include "base_sink.h"
namespace
c11log
{
namespace
sinks
{
class
ostream_sink
:
public
base_sink
{
namespace
c11log
{
namespace
sinks
{
class
ostream_sink
:
public
base_sink
{
public:
explicit
ostream_sink
(
std
::
ostream
&
os
)
:
_ostream
(
os
)
{}
ostream_sink
(
const
ostream_sink
&
)
=
delete
;
ostream_sink
&
operator
=
(
const
ostream_sink
&
)
=
delete
;
ostream_sink
(
const
ostream_sink
&
)
=
delete
;
ostream_sink
&
operator
=
(
const
ostream_sink
&
)
=
delete
;
virtual
~
ostream_sink
()
=
default
;
protected:
virtual
void
_sink_it
(
const
std
::
string
&
msg
)
override
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
_ostream
<<
msg
;
}
std
::
ostream
&
_ostream
;
std
::
mutex
_mutex
;
std
::
mutex
_mutex
;
};
...
...
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