X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Flog.cc;h=ef36a902cbbc76027982bc8a054630ca1e693d38;hb=ba0a895137b630f5d308b123ef886d68090f855d;hp=accf3694d3775d24609c0149658ab7f76b5a7d87;hpb=bb767c7e338414beee132af3e96829c1448e214b;p=dcpomatic.git diff --git a/src/lib/log.cc b/src/lib/log.cc index accf3694d..ef36a902c 100644 --- a/src/lib/log.cc +++ b/src/lib/log.cc @@ -25,12 +25,12 @@ #include #include "log.h" +#include "i18n.h" + using namespace std; -/** @param f Filename to write log to */ -Log::Log (string f) - : _file (f) - , _level (VERBOSE) +Log::Log () + : _level (STANDARD) { } @@ -44,16 +44,33 @@ Log::log (string m, Level l) if (l > _level) { return; } - - ofstream f (_file.c_str(), fstream::app); time_t t; time (&t); string a = ctime (&t); - - f << a.substr (0, a.length() - 1) << ": " << m << "\n"; + + stringstream s; + s << a.substr (0, a.length() - 1) << N_(": ") << m; + do_log (s.str ()); } +void +Log::microsecond_log (string m, Level l) +{ + boost::mutex::scoped_lock lm (_mutex); + + if (l > _level) { + return; + } + + struct timeval tv; + gettimeofday (&tv, 0); + + stringstream s; + s << tv.tv_sec << N_(":") << tv.tv_usec << N_(" ") << m; + do_log (s.str ()); +} + void Log::set_level (Level l) { @@ -61,3 +78,31 @@ Log::set_level (Level l) _level = l; } +void +Log::set_level (string l) +{ + if (l == N_("verbose")) { + set_level (VERBOSE); + return; + } else if (l == N_("timing")) { + set_level (TIMING); + return; + } + + set_level (STANDARD); +} + +/** @param file Filename to write log to */ +FileLog::FileLog (string file) + : _file (file) +{ + +} + +void +FileLog::do_log (string m) +{ + ofstream f (_file.c_str(), fstream::app); + f << m << N_("\n"); +} +