X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Flog.cc;h=e3ffd1cadcc05f4f114e107df4e870d46ce0a3f6;hb=89aeb45b505b9e1b64e205b0498b8f32c2365738;hp=accf3694d3775d24609c0149658ab7f76b5a7d87;hpb=bb767c7e338414beee132af3e96829c1448e214b;p=dcpomatic.git diff --git a/src/lib/log.cc b/src/lib/log.cc index accf3694d..e3ffd1cad 100644 --- a/src/lib/log.cc +++ b/src/lib/log.cc @@ -1,19 +1,20 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2015 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ @@ -21,43 +22,78 @@ * @brief A very simple logging class. */ -#include -#include #include "log.h" +#include "cross.h" +#include "config.h" +#include "string_log_entry.h" +#include +#include -using namespace std; +#include "i18n.h" -/** @param f Filename to write log to */ -Log::Log (string f) - : _file (f) - , _level (VERBOSE) +using std::string; +using std::cout; +using boost::shared_ptr; + +Log::Log () + : _types (0) { + _config_connection = Config::instance()->Changed.connect (boost::bind (&Log::config_changed, this)); + config_changed (); +} +void +Log::config_changed () +{ + set_types (Config::instance()->log_types ()); } -/** @param n String to log */ void -Log::log (string m, Level l) +Log::log (shared_ptr e) { boost::mutex::scoped_lock lm (_mutex); - if (l > _level) { + if ((_types & e->type()) == 0) { 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"; + + do_log (e); } +/** @param n String to log */ void -Log::set_level (Level l) +Log::log (string message, int type) { boost::mutex::scoped_lock lm (_mutex); - _level = l; + + if ((_types & type) == 0) { + return; + } + + shared_ptr e (new StringLogEntry (type, message)); + + do_log (e); +} + +void +Log::dcp_log (dcp::NoteType type, string m) +{ + switch (type) { + case dcp::DCP_PROGRESS: + do_log (shared_ptr (new StringLogEntry (LogEntry::TYPE_GENERAL, m))); + break; + case dcp::DCP_ERROR: + do_log (shared_ptr (new StringLogEntry (LogEntry::TYPE_ERROR, m))); + break; + case dcp::DCP_NOTE: + do_log (shared_ptr (new StringLogEntry (LogEntry::TYPE_WARNING, m))); + break; + } } +void +Log::set_types (int t) +{ + boost::mutex::scoped_lock lm (_mutex); + _types = t; +}