Skip to content

Commit 0358aef

Browse files
authored
Update Logger.cpp
1 parent f438c5a commit 0358aef

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

code/Common/Logger.cpp

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,41 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3030
#include <string>
3131

3232
namespace cppcore {
33-
34-
static void appendDomain(const String &domain, String &logMsg) {
35-
if (!domain.isEmpty()) {
36-
logMsg += '(';
37-
logMsg += domain;
38-
logMsg += ')';
39-
}
40-
}
41-
42-
static ::std::string stripFilename(const ::std::string &filename) {
43-
if (filename.empty()) {
44-
return filename;
33+
namespace {
34+
void appendDomain(const String &domain, String &logMsg) {
35+
if (!domain.isEmpty()) {
36+
logMsg += '(';
37+
logMsg += domain;
38+
logMsg += ')';
39+
}
4540
}
46-
47-
::std::string::size_type pos = filename.find_last_of("/");
48-
if (pos == ::std::string::npos) {
49-
return filename;
41+
42+
::std::string stripFilename(const ::std::string &filename) {
43+
if (filename.empty()) {
44+
return filename;
45+
}
46+
47+
::std::string::size_type pos = filename.find_last_of("/");
48+
if (pos == ::std::string::npos) {
49+
return filename;
50+
}
51+
const ::std::string strippedName = filename.substr(pos + 1, filename.size() - pos - 1);
52+
53+
return strippedName;
5054
}
51-
const ::std::string strippedName = filename.substr(pos + 1, filename.size() - pos - 1);
52-
53-
return strippedName;
54-
}
55-
56-
static void addTraceInfo(const String &file, int line, String &msg) {
57-
if (Logger::getInstance()->getVerboseMode() == Logger::VerboseMode::Trace) {
58-
msg += String(" (", 2);
59-
std::string stripped = stripFilename(file.c_str());
60-
msg += String(stripped.c_str(), stripped.size());
61-
msg += String(", ", 2);
62-
std::stringstream ss;
63-
ss << line;
64-
std::string lineno = ss.str();
65-
msg += String(lineno.c_str(), lineno.size());
66-
msg += ')';
55+
56+
void addTraceInfo(const String &file, int line, String &msg) {
57+
if (Logger::getInstance()->getVerboseMode() == Logger::VerboseMode::Trace) {
58+
msg += String(" (", 2);
59+
std::string stripped = stripFilename(file.c_str());
60+
msg += String(stripped.c_str(), stripped.size());
61+
msg += String(", ", 2);
62+
std::stringstream ss;
63+
ss << line;
64+
std::string lineno = ss.str();
65+
msg += String(lineno.c_str(), lineno.size());
66+
msg += ')';
67+
}
6768
}
6869
}
6970

@@ -82,7 +83,7 @@ bool AbstractLogStream::isActive() const {
8283
Logger *Logger::sLogger = nullptr;
8384

8485
Logger *Logger::create() {
85-
if (nullptr == sLogger) {
86+
if (sLogger == nullptr) {
8687
sLogger = new Logger;
8788
}
8889

@@ -98,7 +99,7 @@ void Logger::set(Logger *logger) {
9899
}
99100

100101
Logger *Logger::getInstance() {
101-
if (nullptr == sLogger) {
102+
if (sLogger == nullptr) {
102103
static_cast<void>(create());
103104
}
104105

@@ -253,8 +254,8 @@ Logger::~Logger() {
253254
}
254255
}
255256

256-
String Logger::getDateTime() {
257-
static const uint32_t Space = 2;
257+
String Logger::getDateTime() const {
258+
static constexpr uint32_t Space = 2;
258259
DateTime currentDateTime;
259260
std::stringstream stream;
260261
stream.fill('0');

0 commit comments

Comments
 (0)