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-11-13 07:59:48 +00:00
|
|
|
// $Id: LogSink.hpp,v 1.3 2005/11/13 07:59:48 cozman Exp $
|
2005-01-27 03:35:23 +00:00
|
|
|
|
2005-02-13 22:12:02 +00:00
|
|
|
#ifndef PHOTON_LOGSINK_HPP
|
|
|
|
#define PHOTON_LOGSINK_HPP
|
2005-01-27 03:35:23 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
|
|
|
|
2005-02-13 22:12:02 +00:00
|
|
|
#include "types.hpp"
|
2005-02-04 08:11:54 +00:00
|
|
|
|
2005-01-27 03:35:23 +00:00
|
|
|
namespace photon
|
|
|
|
{
|
|
|
|
|
2005-01-27 05:24:11 +00:00
|
|
|
// Title: Logging Utilities
|
|
|
|
|
2005-01-27 03:35:23 +00:00
|
|
|
// Enum: LogLevel
|
|
|
|
// Enumeration defining severity of an error.
|
|
|
|
//
|
|
|
|
// Values:
|
|
|
|
// LOG_NOTE - A note, highest priority so that they are always
|
|
|
|
// printed, not used for errors, only for temporary
|
|
|
|
// notes.
|
|
|
|
// LOG_VERBOSE - Verbose warning, lowest priority.
|
|
|
|
// LOG_WARNING - A warning, used for non critical failures.
|
|
|
|
// LOG_ERROR - Normal error, used for potential serious failures.
|
|
|
|
// LOG_CRITICAL - Critical error, used for failures which are threats to
|
|
|
|
// stability.
|
|
|
|
enum LogLevel
|
|
|
|
{
|
|
|
|
LOG_NOTE,
|
|
|
|
LOG_VERBOSE,
|
|
|
|
LOG_WARNING,
|
|
|
|
LOG_ERROR,
|
|
|
|
LOG_CRITICAL
|
|
|
|
};
|
|
|
|
|
|
|
|
// Class: LogSink
|
2005-11-13 07:59:48 +00:00
|
|
|
// Virtual base class for all LogSinks to be used with <Log>, derived classes
|
|
|
|
// must define writeMessage(LogLevel level, std::string string).
|
2005-01-27 03:35:23 +00:00
|
|
|
// A LogSink recieves any messages passed to the log it's registered with.
|
2005-01-27 05:24:11 +00:00
|
|
|
//
|
|
|
|
// Children:
|
|
|
|
// <ConsoleSink>
|
|
|
|
// <TextSink>
|
|
|
|
// <HTMLSink>
|
2005-01-27 03:35:23 +00:00
|
|
|
class LogSink
|
|
|
|
{
|
|
|
|
|
|
|
|
// Group: (Con/De)structors
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Function: LogSink
|
|
|
|
// LogSink constructor, requires a name.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// name_ - Name of LogSink, every LogSink should have a unique name.
|
2005-02-07 01:48:25 +00:00
|
|
|
LogSink(const std::string& name);
|
2005-01-27 03:35:23 +00:00
|
|
|
|
|
|
|
// Function: ~LogSink
|
|
|
|
// Virtual destructor, available to make inheritance safe.
|
|
|
|
virtual ~LogSink();
|
|
|
|
|
|
|
|
// Group: Functions
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Function: writeMessage
|
|
|
|
// Pure virtual function which derived classes must define to write the
|
|
|
|
// message.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// level - <LogLevel> of log event.
|
|
|
|
// msg - String describing log message.
|
2005-02-07 01:48:25 +00:00
|
|
|
virtual void writeMessage(LogLevel level, const std::string& msg)=0;
|
2005-01-27 03:35:23 +00:00
|
|
|
|
|
|
|
// Group: Accessors
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Function: getName
|
|
|
|
// Gets name of the sink.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// Name of the LogSink.
|
|
|
|
std::string getName() const;
|
2005-02-04 08:11:54 +00:00
|
|
|
|
2005-01-27 03:35:23 +00:00
|
|
|
private:
|
|
|
|
std::string name_;
|
|
|
|
|
|
|
|
//assignment left undefined
|
|
|
|
LogSink(const LogSink&);
|
|
|
|
LogSink& operator=(const LogSink&);
|
|
|
|
};
|
|
|
|
|
2005-02-04 08:11:54 +00:00
|
|
|
// Type: LogSinkPtr
|
|
|
|
// Pointer to a log sink, used since LogSink is abstract and will always
|
|
|
|
// be accessed via a pointer.
|
|
|
|
typedef shared_ptr<LogSink> LogSinkPtr;
|
2005-01-27 03:35:23 +00:00
|
|
|
|
|
|
|
// Class: ConsoleSink
|
2005-11-13 07:59:48 +00:00
|
|
|
// <LogSink> to be used with <Log> for simple console output. Note that due
|
|
|
|
// to nature of buffered I/O it is important to flush the stream to see output
|
|
|
|
// in realtime with ConsoleSink
|
2005-01-27 05:24:11 +00:00
|
|
|
//
|
|
|
|
// See Also:
|
|
|
|
// <TextSink>, <HTMLSink>
|
|
|
|
//
|
|
|
|
// Parent:
|
|
|
|
// <LogSink>
|
2005-01-27 03:35:23 +00:00
|
|
|
class ConsoleSink : public LogSink
|
|
|
|
{
|
|
|
|
public:
|
2005-02-07 01:48:25 +00:00
|
|
|
ConsoleSink(const std::string& name);
|
2005-01-27 03:35:23 +00:00
|
|
|
virtual ~ConsoleSink();
|
|
|
|
|
2005-02-07 01:48:25 +00:00
|
|
|
virtual void writeMessage(LogLevel level, const std::string& msg);
|
2005-01-27 03:35:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Class: TextSink
|
|
|
|
// <LogSink> to be used with <Log> for simple text file output.
|
2005-01-27 05:24:11 +00:00
|
|
|
//
|
|
|
|
// See Also:
|
|
|
|
// <ConsoleSink>, <HTMLSink>
|
|
|
|
//
|
|
|
|
// Parent:
|
|
|
|
// <LogSink>
|
2005-01-27 03:35:23 +00:00
|
|
|
class TextSink : public LogSink
|
|
|
|
{
|
|
|
|
public:
|
2005-02-07 01:48:25 +00:00
|
|
|
TextSink(const std::string& name);
|
2005-01-27 03:35:23 +00:00
|
|
|
virtual ~TextSink();
|
|
|
|
|
2005-02-07 01:48:25 +00:00
|
|
|
virtual void writeMessage(LogLevel level, const std::string& msg);
|
2005-01-27 03:35:23 +00:00
|
|
|
private:
|
|
|
|
std::ofstream out_;
|
|
|
|
};
|
|
|
|
|
2005-01-27 05:24:11 +00:00
|
|
|
// Class: HTMLSink
|
2005-01-27 03:35:23 +00:00
|
|
|
// <LogSink> to be used with <Log> for simple HTML output.
|
2005-01-27 05:24:11 +00:00
|
|
|
//
|
|
|
|
// See Also:
|
|
|
|
// <TextSink>, <ConsoleSink>
|
|
|
|
//
|
|
|
|
// Parent:
|
|
|
|
// <LogSink>
|
|
|
|
class HTMLSink : public LogSink
|
2005-01-27 03:35:23 +00:00
|
|
|
{
|
|
|
|
public:
|
2005-02-07 01:48:25 +00:00
|
|
|
HTMLSink(const std::string& name);
|
2005-01-27 05:24:11 +00:00
|
|
|
virtual ~HTMLSink();
|
2005-01-27 03:35:23 +00:00
|
|
|
|
2005-02-07 01:48:25 +00:00
|
|
|
virtual void writeMessage(LogLevel level, const std::string& msg);
|
2005-01-27 03:35:23 +00:00
|
|
|
private:
|
|
|
|
std::ofstream out_;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-02-13 22:12:02 +00:00
|
|
|
#endif //PHOTON_LOGSINK_HPP
|