PILog ready to use
This commit is contained in:
@@ -92,8 +92,10 @@ PILog::~PILog() {
|
||||
void PILog::setDir(const PIString & d) {
|
||||
stopAndWait();
|
||||
log_dir = d;
|
||||
PIDir::make(log_dir);
|
||||
newFile();
|
||||
if (output[File]) {
|
||||
PIDir::make(log_dir);
|
||||
newFile();
|
||||
}
|
||||
start();
|
||||
}
|
||||
|
||||
@@ -164,7 +166,6 @@ PICout PILog::makePICout(PIObject * context, Level cat) {
|
||||
|
||||
|
||||
void PILog::enqueue(const PIString & msg, Level cat) {
|
||||
if (log_file.isClosed()) return;
|
||||
auto t = PIDateTime::fromSystemTime(PISystemTime::current());
|
||||
PIMutexLocker ml(log_mutex);
|
||||
queue.enqueue({cat, t, msg});
|
||||
@@ -190,9 +191,11 @@ void PILog::newFile() {
|
||||
|
||||
|
||||
void PILog::run() {
|
||||
if (split_tm.elapsed() >= split_time) {
|
||||
split_tm.reset();
|
||||
newFile();
|
||||
if (output[File]) {
|
||||
if (split_tm.elapsed() >= split_time) {
|
||||
split_tm.reset();
|
||||
newFile();
|
||||
}
|
||||
}
|
||||
log_mutex.lock();
|
||||
if (queue.isEmpty()) {
|
||||
@@ -210,10 +213,17 @@ void PILog::run() {
|
||||
auto qi = queue.dequeue();
|
||||
log_mutex.unlock();
|
||||
auto str = entryToString(qi);
|
||||
log_ts << str << "\n";
|
||||
if (qi.cat == Level::Error)
|
||||
piCerr << str;
|
||||
else
|
||||
piCout << str;
|
||||
if (log_file.isOpened()) log_ts << str << "\n";
|
||||
if (output[Console]) {
|
||||
PICout out(qi.cat == Level::Error ? piCerr : piCout);
|
||||
if (color_console) {
|
||||
switch (qi.cat) {
|
||||
case Level::Error: out << PICoutManipulators::Red; break;
|
||||
case Level::Warning: out << PICoutManipulators::Yellow; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
out << str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user