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
a626ebbb
Commit
a626ebbb
authored
Feb 15, 2017
by
Jean-Michaël Celerier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace static global std::string arrays by Meyer singletons. This improves thread-safety.
parent
054eb555
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
9 deletions
+22
-9
include/spdlog/details/pattern_formatter_impl.h
include/spdlog/details/pattern_formatter_impl.h
+22
-9
No files found.
include/spdlog/details/pattern_formatter_impl.h
View file @
a626ebbb
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include <thread>
#include <thread>
#include <utility>
#include <utility>
#include <vector>
#include <vector>
#include <array>
namespace
spdlog
namespace
spdlog
{
{
...
@@ -78,42 +79,54 @@ static int to12h(const tm& t)
...
@@ -78,42 +79,54 @@ static int to12h(const tm& t)
}
}
//Abbreviated weekday name
//Abbreviated weekday name
static
const
std
::
string
days
[]
{
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
};
static
const
auto
&
days
()
{
static
std
::
array
<
std
::
string
,
7
>
arr
{
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
};
return
arr
;
}
class
a_formatter
:
public
flag_formatter
class
a_formatter
:
public
flag_formatter
{
{
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
)
override
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
)
override
{
{
msg
.
formatted
<<
days
[
tm_time
.
tm_wday
];
msg
.
formatted
<<
days
()
[
tm_time
.
tm_wday
];
}
}
};
};
//Full weekday name
//Full weekday name
static
const
std
::
string
full_days
[]
{
"Sunday"
,
"Monday"
,
"Tuesday"
,
"Wednesday"
,
"Thursday"
,
"Friday"
,
"Saturday"
};
static
const
auto
&
full_days
()
{
static
std
::
array
<
std
::
string
,
7
>
arr
{
"Sunday"
,
"Monday"
,
"Tuesday"
,
"Wednesday"
,
"Thursday"
,
"Friday"
,
"Saturday"
};
return
arr
;
}
class
A_formatter
:
public
flag_formatter
class
A_formatter
:
public
flag_formatter
{
{
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
)
override
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
)
override
{
{
msg
.
formatted
<<
full_days
[
tm_time
.
tm_wday
];
msg
.
formatted
<<
full_days
()
[
tm_time
.
tm_wday
];
}
}
};
};
//Abbreviated month
//Abbreviated month
static
const
std
::
string
months
[]
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"June"
,
"July"
,
"Aug"
,
"Sept"
,
"Oct"
,
"Nov"
,
"Dec"
};
static
const
auto
&
months
()
{
static
std
::
array
<
std
::
string
,
12
>
arr
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"June"
,
"July"
,
"Aug"
,
"Sept"
,
"Oct"
,
"Nov"
,
"Dec"
};
return
arr
;
}
class
b_formatter
:
public
flag_formatter
class
b_formatter
:
public
flag_formatter
{
{
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
)
override
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
)
override
{
{
msg
.
formatted
<<
months
[
tm_time
.
tm_mon
];
msg
.
formatted
<<
months
()
[
tm_time
.
tm_mon
];
}
}
};
};
//Full month name
//Full month name
static
const
std
::
string
full_months
[]
{
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
};
static
const
auto
&
full_months
()
{
static
std
::
array
<
std
::
string
,
12
>
arr
{
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
};
return
arr
;
}
class
B_formatter
:
public
flag_formatter
class
B_formatter
:
public
flag_formatter
{
{
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
)
override
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
)
override
{
{
msg
.
formatted
<<
full_months
[
tm_time
.
tm_mon
];
msg
.
formatted
<<
full_months
()
[
tm_time
.
tm_mon
];
}
}
};
};
...
@@ -138,7 +151,7 @@ class c_formatter:public flag_formatter
...
@@ -138,7 +151,7 @@ class c_formatter:public flag_formatter
{
{
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
)
override
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
)
override
{
{
msg
.
formatted
<<
days
[
tm_time
.
tm_wday
]
<<
' '
<<
months
[
tm_time
.
tm_mon
]
<<
' '
<<
tm_time
.
tm_mday
<<
' '
;
msg
.
formatted
<<
days
()[
tm_time
.
tm_wday
]
<<
' '
<<
months
()
[
tm_time
.
tm_mon
]
<<
' '
<<
tm_time
.
tm_mday
<<
' '
;
pad_n_join
(
msg
.
formatted
,
tm_time
.
tm_hour
,
tm_time
.
tm_min
,
tm_time
.
tm_sec
,
':'
)
<<
' '
<<
tm_time
.
tm_year
+
1900
;
pad_n_join
(
msg
.
formatted
,
tm_time
.
tm_hour
,
tm_time
.
tm_min
,
tm_time
.
tm_sec
,
':'
)
<<
' '
<<
tm_time
.
tm_year
+
1900
;
}
}
};
};
...
...
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