summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-09-18 02:07:59 +0100
committerCarl Hetherington <cth@carlh.net>2012-09-18 02:07:59 +0100
commit3c1b239453936128d1711ffa063ad4e1617b3e40 (patch)
tree060213367c651ca0ddccf1d9470b35886a687f6e /src/lib
parent48794870183ac5c0dd2b4acc1f9c2e5d7349f284 (diff)
Sort of working log window.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dcp_video_frame.cc4
-rw-r--r--src/lib/film.cc2
-rw-r--r--src/lib/log.cc29
-rw-r--r--src/lib/log.h27
-rw-r--r--src/lib/server.cc6
-rw-r--r--src/lib/server.h4
6 files changed, 47 insertions, 25 deletions
diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc
index 91c441543..b128f6fa0 100644
--- a/src/lib/dcp_video_frame.cc
+++ b/src/lib/dcp_video_frame.cc
@@ -277,7 +277,7 @@ DCPVideoFrame::encode_locally ()
{
stringstream s;
- s << "Finished locally-encoded frame " << _frame << " length " << cio_tell (_cio);
+ s << "Finished locally-encoded frame " << _frame;
_log->log (s.str ());
}
@@ -342,7 +342,7 @@ DCPVideoFrame::encode_remotely (ServerDescription const * serv)
{
stringstream s;
- s << "Finished remotely-encoded frame " << _frame << " length " << e->size();
+ s << "Finished remotely-encoded frame " << _frame;
_log->log (s.str ());
}
diff --git a/src/lib/film.cc b/src/lib/film.cc
index f8a3b192d..3b74f1888 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -88,7 +88,7 @@ Film::Film (string d, bool must_exist)
read_metadata ();
- _log = new Log (_state.file ("log"));
+ _log = new FileLog (_state.file ("log"));
}
/** Copy constructor */
diff --git a/src/lib/log.cc b/src/lib/log.cc
index accf3694d..7f1eea206 100644
--- a/src/lib/log.cc
+++ b/src/lib/log.cc
@@ -27,10 +27,8 @@
using namespace std;
-/** @param f Filename to write log to */
-Log::Log (string f)
- : _file (f)
- , _level (VERBOSE)
+Log::Log ()
+ : _level (VERBOSE)
{
}
@@ -45,13 +43,13 @@ Log::log (string m, Level l)
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) << ": " << m;
+ do_log (s.str ());
}
void
@@ -61,3 +59,18 @@ Log::set_level (Level l)
_level = l;
}
+
+/** @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";
+}
+
diff --git a/src/lib/log.h b/src/lib/log.h
index d32b368f5..2a242e24c 100644
--- a/src/lib/log.h
+++ b/src/lib/log.h
@@ -29,15 +29,11 @@
/** @class Log
* @brief A very simple logging class.
- *
- * This class simply accepts log messages and writes them to a file.
- * Its single nod to complexity is that it has a mutex to prevent
- * multi-thread logging from clashing.
*/
class Log
{
public:
- Log (std::string f);
+ Log ();
enum Level {
STANDARD = 0,
@@ -48,13 +44,26 @@ public:
void set_level (Level l);
-private:
- /** mutex to prevent simultaneous writes to the file */
+protected:
+ /** mutex to protect the log */
boost::mutex _mutex;
- /** filename to write to */
- std::string _file;
+
+private:
+ virtual void do_log (std::string m) = 0;
+
/** level above which to ignore log messages */
Level _level;
};
+class FileLog : public Log
+{
+public:
+ FileLog (std::string file);
+
+private:
+ void do_log (std::string m);
+ /** filename to write to */
+ std::string _file;
+};
+
#endif
diff --git a/src/lib/server.cc b/src/lib/server.cc
index f4aaa25e1..9e43601c4 100644
--- a/src/lib/server.cc
+++ b/src/lib/server.cc
@@ -62,8 +62,8 @@ ServerDescription::as_metadata () const
return s.str ();
}
-Server::Server ()
- : _log ("servomatic.log")
+Server::Server (Log* log)
+ : _log (log)
{
}
@@ -129,7 +129,7 @@ Server::process (shared_ptr<asio::ip::tcp::socket> socket)
image->hash ("Image for encoding (as received by server)");
#endif
- DCPVideoFrame dcp_video_frame (image, out_size, padding, scaler, frame, frames_per_second, post_process, colour_lut_index, j2k_bandwidth, &_log);
+ DCPVideoFrame dcp_video_frame (image, out_size, padding, scaler, frame, frames_per_second, post_process, colour_lut_index, j2k_bandwidth, _log);
shared_ptr<EncodedData> encoded = dcp_video_frame.encode_locally ();
encoded->send (socket);
diff --git a/src/lib/server.h b/src/lib/server.h
index 8c0f86ebb..58cfe0b3f 100644
--- a/src/lib/server.h
+++ b/src/lib/server.h
@@ -74,7 +74,7 @@ private:
class Server
{
public:
- Server ();
+ Server (Log* log);
void run ();
@@ -86,5 +86,5 @@ private:
std::list<boost::shared_ptr<boost::asio::ip::tcp::socket> > _queue;
boost::mutex _worker_mutex;
boost::condition _worker_condition;
- Log _log;
+ Log* _log;
};