2005-01-27 03:35:23 +00:00
|
|
|
//This file is part of Photon (http://photon.sourceforge.net)
|
|
|
|
//Copyright (C) 2004-2005 James Turk
|
|
|
|
//
|
|
|
|
// Author:
|
|
|
|
// James Turk (jpt2433@rit.edu)
|
|
|
|
//
|
|
|
|
// Version:
|
2005-02-27 05:53:01 +00:00
|
|
|
// $Id: Log.hpp,v 1.3 2005/02/27 05:53:01 cozman Exp $
|
2005-01-27 03:35:23 +00:00
|
|
|
|
2005-02-13 22:12:02 +00:00
|
|
|
#ifndef PHOTON_LOG_HPP
|
|
|
|
#define PHOTON_LOG_HPP
|
2005-01-27 03:35:23 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <sstream>
|
|
|
|
|
2005-02-27 05:53:01 +00:00
|
|
|
#include "util/Singleton.hpp"
|
2005-02-13 22:12:02 +00:00
|
|
|
#include "LogSink.hpp"
|
2005-01-27 03:35:23 +00:00
|
|
|
|
|
|
|
namespace photon
|
|
|
|
{
|
|
|
|
|
|
|
|
// Class: Log
|
2005-02-07 01:48:25 +00:00
|
|
|
// Log class for photon, Log passes all messages to any attached <LogSinks>,
|
|
|
|
// which can then take care of any output which is desired.
|
2005-02-27 05:53:01 +00:00
|
|
|
class Log : public util::Singleton<Log>
|
2005-01-27 03:35:23 +00:00
|
|
|
{
|
|
|
|
// Group: Sink Maintenance
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Function: addSink
|
|
|
|
// Adds a sink to the Log, sinks are given access to all messages passed
|
|
|
|
// into the log.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// sink - Pointer to <LogSink> to add to Log.
|
2005-02-04 08:11:54 +00:00
|
|
|
void addSink(LogSinkPtr sink);
|
2005-01-27 03:35:23 +00:00
|
|
|
|
|
|
|
// Function: removeSink
|
|
|
|
// Remove a sink from the log by name.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// sinkName - Name of sink to remove.
|
2005-02-07 01:48:25 +00:00
|
|
|
void removeSink(const std::string& sinkName);
|
2005-01-27 03:35:23 +00:00
|
|
|
|
|
|
|
// Function: removeSink
|
|
|
|
// Remove a sink from the log.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// sink - Pointer to sink to remove.
|
2005-02-04 08:11:54 +00:00
|
|
|
void removeSink(LogSinkPtr sink);
|
2005-01-27 03:35:23 +00:00
|
|
|
|
|
|
|
// Function: removeSinks
|
|
|
|
// Remove all sinks from log.
|
|
|
|
void removeSinks();
|
|
|
|
|
|
|
|
// Group: Stream Access
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Function: note
|
|
|
|
// Accesses stream, any messages passed into note are given to associated
|
|
|
|
// <LogSinks> with a <LogLevel> of LOG_NOTE.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// Stream to pass errors to.
|
|
|
|
std::ostream& note();
|
|
|
|
|
|
|
|
// Function: verbose
|
|
|
|
// Accesses stream, any messages passed into verbose are given to
|
|
|
|
// associated <LogSinks> with a <LogLevel> of LOG_VERBOSE.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// Stream to pass errors to.
|
|
|
|
std::ostream& verbose();
|
|
|
|
|
|
|
|
// Function: warning
|
|
|
|
// Accesses stream, any messages passed into warning are given to
|
|
|
|
// associated <LogSinks> with a <LogLevel> of LOG_WARNING.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// Stream to pass errors to.
|
|
|
|
std::ostream& warning();
|
|
|
|
|
|
|
|
// Function: error
|
|
|
|
// Accesses stream, any messages passed into error are given to associated
|
|
|
|
// <LogSinks> with a <LogLevel> of LOG_ERROR.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// Stream to pass errors to.
|
|
|
|
std::ostream& error();
|
|
|
|
|
|
|
|
// Function: critical
|
|
|
|
// Accesses stream, any messages passed into critical are given to
|
|
|
|
// associated <LogSinks> with a <LogLevel> of LOG_CRITICAL.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// Stream to pass errors to.
|
|
|
|
std::ostream& critical();
|
|
|
|
|
|
|
|
// Function: flush
|
|
|
|
// Flushes the log, is generally not required. Output is handed to the
|
|
|
|
// sinks when flush is called.
|
|
|
|
void flush();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::stringstream buffer_;
|
|
|
|
LogLevel lastLevel_;
|
2005-02-04 08:11:54 +00:00
|
|
|
std::list<LogSinkPtr> sinks_;
|
2005-02-27 05:53:01 +00:00
|
|
|
|
|
|
|
// singleton stuff
|
|
|
|
private:
|
|
|
|
friend class util::Singleton<Log>;
|
|
|
|
friend class std::auto_ptr<Log>;
|
|
|
|
Log();
|
|
|
|
~Log();
|
2005-01-27 03:35:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-02-13 22:12:02 +00:00
|
|
|
#endif //PHOTON_LOG_HPP
|