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
20cb73e9
Commit
20cb73e9
authored
Aug 22, 2016
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
disable syslog by default (enable by #define SPDLOG_ENABLE_SYSLOG )
parent
c68a0de2
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
77 deletions
+81
-77
example.cpp
example/example.cpp
+1
-0
common.h
include/spdlog/common.h
+53
-63
mpmc_bounded_q.h
include/spdlog/details/mpmc_bounded_q.h
+16
-3
os.h
include/spdlog/details/os.h
+2
-3
tweakme.h
include/spdlog/tweakme.h
+9
-8
No files found.
example/example.cpp
View file @
20cb73e9
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
//
//
// spdlog usage example
// spdlog usage example
//
//
//
#include "spdlog/spdlog.h"
#include "spdlog/spdlog.h"
#include <iostream>
#include <iostream>
...
...
include/spdlog/common.h
View file @
20cb73e9
...
@@ -37,46 +37,36 @@
...
@@ -37,46 +37,36 @@
#define DEPRECATED
#define DEPRECATED
#endif
#endif
#include <spdlog/tweakme.h>
#ifndef SPDLOG_ENABLE_SYSLOG
#if defined (__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#define SPDLOG_ENABLE_SYSLOG
#elif defined(sun) || defined(__sun)
#define SPDLOG_ENABLE_SYSLOG
#endif
#endif
#include <spdlog/fmt/fmt.h>
#include <spdlog/fmt/fmt.h>
namespace
spdlog
namespace
spdlog
{
{
class
formatter
;
class
formatter
;
namespace
sinks
namespace
sinks
{
{
class
sink
;
class
sink
;
}
}
using
log_clock
=
std
::
chrono
::
system_clock
;
using
log_clock
=
std
::
chrono
::
system_clock
;
using
sink_ptr
=
std
::
shared_ptr
<
sinks
::
sink
>
;
using
sink_ptr
=
std
::
shared_ptr
<
sinks
::
sink
>
;
using
sinks_init_list
=
std
::
initializer_list
<
sink_ptr
>
;
using
sinks_init_list
=
std
::
initializer_list
<
sink_ptr
>
;
using
formatter_ptr
=
std
::
shared_ptr
<
spdlog
::
formatter
>
;
using
formatter_ptr
=
std
::
shared_ptr
<
spdlog
::
formatter
>
;
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
using
level_t
=
details
::
null_atomic_int
;
using
level_t
=
details
::
null_atomic_int
;
#else
#else
using
level_t
=
std
::
atomic_int
;
using
level_t
=
std
::
atomic_int
;
#endif
#endif
using
log_err_handler
=
std
::
function
<
void
(
const
std
::
string
&
err_msg
)
>
;
using
log_err_handler
=
std
::
function
<
void
(
const
std
::
string
&
err_msg
)
>
;
//Log level enum
//Log level enum
namespace
level
namespace
level
{
{
typedef
enum
typedef
enum
{
{
trace
=
0
,
trace
=
0
,
debug
=
1
,
debug
=
1
,
info
=
2
,
info
=
2
,
...
@@ -84,47 +74,47 @@ typedef enum
...
@@ -84,47 +74,47 @@ typedef enum
err
=
4
,
err
=
4
,
critical
=
5
,
critical
=
5
,
off
=
6
off
=
6
}
level_enum
;
}
level_enum
;
static
const
char
*
level_names
[]
{
"trace"
,
"debug"
,
"info"
,
"warning"
,
"error"
,
"critical"
,
"off"
};
static
const
char
*
level_names
[]{
"trace"
,
"debug"
,
"info"
,
"warning"
,
"error"
,
"critical"
,
"off"
};
static
const
char
*
short_level_names
[]
{
"T"
,
"D"
,
"I"
,
"W"
,
"E"
,
"C"
,
"O"
};
static
const
char
*
short_level_names
[]{
"T"
,
"D"
,
"I"
,
"W"
,
"E"
,
"C"
,
"O"
};
inline
const
char
*
to_str
(
spdlog
::
level
::
level_enum
l
)
inline
const
char
*
to_str
(
spdlog
::
level
::
level_enum
l
)
{
{
return
level_names
[
l
];
return
level_names
[
l
];
}
}
inline
const
char
*
to_short_str
(
spdlog
::
level
::
level_enum
l
)
inline
const
char
*
to_short_str
(
spdlog
::
level
::
level_enum
l
)
{
{
return
short_level_names
[
l
];
return
short_level_names
[
l
];
}
}
}
//level
}
//level
//
//
// Async overflow policy - block by default.
// Async overflow policy - block by default.
//
//
enum
class
async_overflow_policy
enum
class
async_overflow_policy
{
{
block_retry
,
// Block / yield / sleep until message can be enqueued
block_retry
,
// Block / yield / sleep until message can be enqueued
discard_log_msg
// Discard the message it enqueue fails
discard_log_msg
// Discard the message it enqueue fails
};
};
//
//
// Log exception
// Log exception
//
//
namespace
details
namespace
details
{
{
namespace
os
namespace
os
{
{
std
::
string
errno_str
(
int
err_num
);
std
::
string
errno_str
(
int
err_num
);
}
}
}
}
class
spdlog_ex
:
public
std
::
exception
class
spdlog_ex
:
public
std
::
exception
{
{
public
:
public
:
spdlog_ex
(
const
std
::
string
&
msg
)
:
_msg
(
msg
)
spdlog_ex
(
const
std
::
string
&
msg
)
:
_msg
(
msg
)
{}
{}
spdlog_ex
(
const
std
::
string
&
msg
,
int
last_errno
)
spdlog_ex
(
const
std
::
string
&
msg
,
int
last_errno
)
...
@@ -135,18 +125,18 @@ public:
...
@@ -135,18 +125,18 @@ public:
{
{
return
_msg
.
c_str
();
return
_msg
.
c_str
();
}
}
private
:
private
:
std
::
string
_msg
;
std
::
string
_msg
;
};
};
//
//
// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
//
//
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
using
filename_t
=
std
::
wstring
;
using
filename_t
=
std
::
wstring
;
#else
#else
using
filename_t
=
std
::
string
;
using
filename_t
=
std
::
string
;
#endif
#endif
...
...
include/spdlog/details/mpmc_bounded_q.h
View file @
20cb73e9
...
@@ -60,7 +60,8 @@ public:
...
@@ -60,7 +60,8 @@ public:
using
item_type
=
T
;
using
item_type
=
T
;
mpmc_bounded_queue
(
size_t
buffer_size
)
mpmc_bounded_queue
(
size_t
buffer_size
)
:
buffer_
(
new
cell_t
[
buffer_size
]),
:
max_size_
(
buffer_size
),
buffer_
(
new
cell_t
[
buffer_size
]),
buffer_mask_
(
buffer_size
-
1
)
buffer_mask_
(
buffer_size
-
1
)
{
{
//queue size must be power of two
//queue size must be power of two
...
@@ -132,6 +133,16 @@ public:
...
@@ -132,6 +133,16 @@ public:
return
true
;
return
true
;
}
}
size_t
approx_size
()
{
size_t
first_pos
=
dequeue_pos_
.
load
(
std
::
memory_order_relaxed
);
size_t
last_pos
=
enqueue_pos_
.
load
(
std
::
memory_order_relaxed
);
if
(
last_pos
<=
first_pos
)
return
0
;
auto
size
=
last_pos
-
first_pos
;
return
size
<
max_size_
?
size
:
max_size_
;
}
private
:
private
:
struct
cell_t
struct
cell_t
{
{
...
@@ -139,6 +150,8 @@ private:
...
@@ -139,6 +150,8 @@ private:
T
data_
;
T
data_
;
};
};
size_t
const
max_size_
;
static
size_t
const
cacheline_size
=
64
;
static
size_t
const
cacheline_size
=
64
;
typedef
char
cacheline_pad_t
[
cacheline_size
];
typedef
char
cacheline_pad_t
[
cacheline_size
];
...
@@ -151,8 +164,8 @@ private:
...
@@ -151,8 +164,8 @@ private:
std
::
atomic
<
size_t
>
dequeue_pos_
;
std
::
atomic
<
size_t
>
dequeue_pos_
;
cacheline_pad_t
pad3_
;
cacheline_pad_t
pad3_
;
mpmc_bounded_queue
(
mpmc_bounded_queue
const
&
);
mpmc_bounded_queue
(
mpmc_bounded_queue
const
&
)
=
delete
;
void
operator
=
(
mpmc_bounded_queue
const
&
);
void
operator
=
(
mpmc_bounded_queue
const
&
)
=
delete
;
};
};
}
// ns details
}
// ns details
...
...
include/spdlog/details/os.h
View file @
20cb73e9
...
@@ -250,7 +250,6 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime())
...
@@ -250,7 +250,6 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime())
offset
-=
tzinfo
.
StandardBias
;
offset
-=
tzinfo
.
StandardBias
;
return
offset
;
return
offset
;
#else
#else
long
int
offset_seconds
;
#if defined(sun) || defined(__sun)
#if defined(sun) || defined(__sun)
// 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris
// 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris
...
@@ -280,9 +279,9 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime())
...
@@ -280,9 +279,9 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime())
}
}
};
};
offset_seconds
=
helper
::
calculate_gmt_offset
(
tm
);
long
int
offset_seconds
=
helper
::
calculate_gmt_offset
(
tm
);
#else
#else
offset_seconds
=
tm
.
tm_gmtoff
;
long
int
offset_seconds
=
tm
.
tm_gmtoff
;
#endif
#endif
return
static_cast
<
int
>
(
offset_seconds
/
60
);
return
static_cast
<
int
>
(
offset_seconds
/
60
);
...
...
include/spdlog/tweakme.h
View file @
20cb73e9
...
@@ -11,13 +11,6 @@
...
@@ -11,13 +11,6 @@
//
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// By default, syslog sink is only enabled on tested operating systems.
// Uncomment to enable it unconditionally.
//
// #define SPDLOG_ENABLE_SYSLOG
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Under Linux, the much faster CLOCK_REALTIME_COARSE clock can be used.
// Under Linux, the much faster CLOCK_REALTIME_COARSE clock can be used.
...
@@ -56,7 +49,6 @@
...
@@ -56,7 +49,6 @@
// #define SPDLOG_NO_NAME
// #define SPDLOG_NO_NAME
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Uncomment to enable the SPDLOG_DEBUG/SPDLOG_TRACE macros.
// Uncomment to enable the SPDLOG_DEBUG/SPDLOG_TRACE macros.
//
//
...
@@ -100,3 +92,12 @@
...
@@ -100,3 +92,12 @@
//
//
// #define SPDLOG_FMT_EXTERNAL
// #define SPDLOG_FMT_EXTERNAL
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Uncomment to enable syslog (disabled by default)
//
// #define SPDLOG_ENABLE_SYSLOG
///////////////////////////////////////////////////////////////////////////////
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