cpp_photon/include/Log.hpp

121 lines
2.9 KiB
C++
Raw Normal View History

//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-02-13 22:12:02 +00:00
#ifndef PHOTON_LOG_HPP
#define PHOTON_LOG_HPP
#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"
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>
{
// 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.
void addSink(LogSinkPtr sink);
// 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);
// Function: removeSink
// Remove a sink from the log.
//
// Parameters:
// sink - Pointer to sink to remove.
void removeSink(LogSinkPtr sink);
// 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_;
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-02-13 22:12:02 +00:00
#endif //PHOTON_LOG_HPP