Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ compiler:

env:
- BUILD_TYPE=Debug
CXXFLAGS="${CXXFLAGS} -pthread"
- BUILD_TYPE=Release
CXXFLAGS="${CXXFLAGS} -pthread"

install:
# Prerequisites
Expand All @@ -15,4 +17,4 @@ install:
script:
- cmake -Hsamples -Bbuild -DCMAKE_BUILD_TYPE=$BUILD_TYPE
- cd build
- make
- make
3 changes: 2 additions & 1 deletion include/plog/Appenders/RollingFileAppender.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace plog

virtual void write(const Record& record)
{
const std::string line = Converter::convert(Formatter::format(record));
util::MutexLock lock(m_mutex);

if (m_firstWrite)
Expand All @@ -32,7 +33,7 @@ namespace plog
rollLogFiles();
}

int bytesWritten = m_file.write(Converter::convert(Formatter::format(record)));
int bytesWritten = m_file.write(line);

if (bytesWritten > 0)
{
Expand Down
16 changes: 10 additions & 6 deletions include/plog/Formatters/TxtFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ namespace plog
tm t;
util::localtime_s(&t, &record.getTime().time);

char timeBuffer[32];
strftime(timeBuffer, sizeof(timeBuffer), "%Y-%m-%d %T", &t);

util::nstringstream ss;
ss << t.tm_year + 1900 << "-" << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mon + 1 << "-" << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mday << " ";
ss << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_hour << ":" << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_min << ":" << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_sec << "." << std::setfill(PLOG_NSTR('0')) << std::setw(3) << record.getTime().millitm << " ";
ss << std::setfill(PLOG_NSTR(' ')) << std::setw(5) << std::left << getSeverityName(record.getSeverity()) << " ";
ss << "[" << record.getTid() << "] ";
ss << "[" << record.getFunc().c_str() << "@" << record.getLine() << "] ";
ss << record.getMessage().c_str() << "\n";
ss << timeBuffer << PLOG_NSTR('.') << std::setfill(PLOG_NSTR('0')) << std::setw(3)
<< record.getTime().millitm << PLOG_NSTR(' ')
<< std::setfill(PLOG_NSTR(' ')) << std::setw(5) << std::left << getSeverityName(record.getSeverity())
<< PLOG_NSTR(' ')
<< PLOG_NSTR('[') << record.getTid() << PLOG_NSTR("] ")
<< PLOG_NSTR('[') << record.getFunc().c_str() << PLOG_NSTR('@') << record.getLine() << PLOG_NSTR("] ")
<< record.getMessage().c_str() << PLOG_NSTR('\n');

return ss.str();
}
Expand Down
19 changes: 10 additions & 9 deletions include/plog/Severity.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "Util.h"

namespace plog
{
Expand All @@ -12,25 +13,25 @@ namespace plog
debug = 5,
verbose = 6
};
inline const char* getSeverityName(Severity severity)

inline util::nstring::const_pointer getSeverityName(Severity severity)
{
switch (severity)
{
case fatal:
return "FATAL";
return PLOG_NSTR("FATAL");
case error:
return "ERROR";
return PLOG_NSTR("ERROR");
case warning:
return "WARN";
return PLOG_NSTR("WARN");
case info:
return "INFO";
return PLOG_NSTR("INFO");
case debug:
return "DEBUG";
return PLOG_NSTR("DEBUG");
case verbose:
return "VERB";
return PLOG_NSTR("VERB");
default:
return "NONE";
return PLOG_NSTR("NONE");
}
}
}
9 changes: 8 additions & 1 deletion include/plog/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,19 @@ namespace plog
friend class MutexLock;

private:
enum { PTHREAD_SPINLOCK_COUNT = 500 };

void lock()
{
#ifdef _WIN32
::EnterCriticalSection(&m_sync);
#else
::pthread_mutex_lock(&m_sync);
bool isLocked = false;
for (unsigned i=0; i<PTHREAD_SPINLOCK_COUNT && !isLocked; ++i,pthread_yield())
isLocked = ::pthread_mutex_trylock(&m_sync) == 0;

if (!isLocked)
::pthread_mutex_lock(&m_sync);
#endif
}

Expand Down