Files

214 lines
5.2 KiB
C++

// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
//
// This software owned by Onix Solutions Limited [OnixS] and is
// protected by copyright law and international copyright treaties.
//
// Access to and use of the software is governed by the terms of the applicable
// OnixS Software Services Agreement (the Agreement) and Customer end user license
// agreements granting a non-assignable, non-transferable and non-exclusive license
// to use the software for it's own data processing purposes under the terms defined
// in the Agreement.
//
// Except as otherwise granted within the terms of the Agreement, copying or
// reproduction of any part of this source code or associated reference material
// to any other location for further reproduction or redistribution, and any
// amendments to this copyright notice, are expressly prohibited.
//
// Any reproduction or redistribution for sale or hiring of the Software not in
// accordance with the terms of the Agreement is a violation of copyright law.
//
#pragma once
#include <OnixS/CME/MDH/Integral.h>
#include <OnixS/CME/MDH/String.h>
ONIXS_CMEMDH_NAMESPACE_BEGIN
/// Defines severity levels for log entries.
ONIXS_CMEMDH_LTWT_STRUCT LogSeverity
{
/// Enumeration base.
typedef UInt32 Base;
/// Log alternates.
enum Enum
{
/// Only important information like
/// warnings and errors will be logged.
///
/// Mode is not suitable for further log
/// replays, because no market data is stored.
Important = 10,
/// Handler will log miscellaneous aspects
/// related with its execution like changes
/// in state, network data obtained, etc. All
/// critical important information like warnings
/// and errors will be logged as well.
///
/// Most suitable mode to produce logs for further replay.
Regular = 50,
/// In addition to the data logged in 'Regular'
/// mode, Handler will output additional information
/// like step-by-step changes into books, step-by-step
/// processing of received network packets.
Debug = 100
};
};
/// Serializes log severity constant.
ONIXS_CMEMDH_EXPORTED
void
toStr(
std::string&,
LogSeverity::Enum);
/// Serializes log severity constant.
inline
std::string
toStr(
LogSeverity::Enum mode)
{
std::string str;
toStr(str, mode);
return str;
}
/// Deserializes log severity constant.
ONIXS_CMEMDH_EXPORTED
bool
fromStr(
LogSeverity::Enum&,
const Char*,
size_t);
/// Categories for information being logged.
ONIXS_CMEMDH_LTWT_STRUCT LogCategory
{
// Enumeration base.
typedef UInt32 Base;
/// Categories for information being logged.
enum Enum
{
/// Log entry represents an error.
Error,
/// Log entry represents a warning.
Warning,
/// Log entry represents informational message.
Info,
/// Log entry represents debug information.
Debug
};
};
/// Serializes log category constant.
ONIXS_CMEMDH_EXPORTED
void
toStr(
std::string&,
LogCategory::Enum);
/// Serializes log category constant.
inline
std::string
toStr(
LogCategory::Enum mode)
{
std::string str;
toStr(str, mode);
return str;
}
/// Deserializes log category constant.
ONIXS_CMEMDH_EXPORTED
bool
fromStr(
LogCategory::Enum&,
const Char*,
size_t);
/// Abstraction of log entry in logging services.
ONIXS_CMEMDH_EXPORTED_CLASS LogEntry
{
public:
/// Specifies category of information being logged.
virtual void category(LogCategory::Enum) = 0;
/// Specifies source of information being logged.
virtual void source(const StrRef&) = 0;
/// Editable text to be a message of log entry.
virtual std::string& message() = 0;
/// Commits entry into a log and releases the instance.
///
/// Once given member is invoked, further invocation
/// of other members is not allowed as instance may be
/// disposed and thus do not exist anymore.
virtual void commit() = 0;
protected:
/// Life-time is managed by Logger.
LogEntry()
{
}
/// Life-time is managed by Logger.
~LogEntry()
{
}
private:
// Object copying is not supposed.
LogEntry(const LogEntry&);
LogEntry& operator =(const LogEntry&);
};
/// Abstraction of logger.
ONIXS_CMEMDH_EXPORTED_CLASS Logger
{
// Object copying is not supposed.
Logger(const Logger&);
Logger& operator =(const Logger&);
protected:
/// Only descendants are to be created.
Logger()
{
}
/// Only descendants are to be created.
~Logger()
{
}
public:
/// Adds entry to the log.
///
/// Actual content can be added through the
/// interface of LogEntry and LogEvent classes.
///
/// @return Instance of LogEntry to build message
/// being added into the log or NULL if severity
/// of entry being added does not correspond to
/// logger's configuration.
virtual
LogEntry*
addEntry(
LogSeverity::Enum) = 0;
};
ONIXS_CMEMDH_NAMESPACE_END