150 lines
4.2 KiB
C++
150 lines
4.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 <memory>
|
|
|
|
#include <OnixS/CME/MDH/Integral.h>
|
|
#include <OnixS/CME/MDH/Logger.h>
|
|
#include <OnixS/CME/MDH/Time.h>
|
|
|
|
ONIXS_CMEMDH_NAMESPACE_BEGIN
|
|
|
|
/// Base parameters affecting synchronous logging services.
|
|
ONIXS_CMEMDH_LTWT_CLASS FileLoggerSettings
|
|
{
|
|
std::string filename_;
|
|
UInt64 fileSizeLimit_;
|
|
|
|
LogSeverity::Enum severity_;
|
|
|
|
WatchService* watch_;
|
|
|
|
public:
|
|
/// Initializes parameters with default values.
|
|
FileLoggerSettings()
|
|
: filename_()
|
|
, fileSizeLimit_(2145386496)
|
|
, severity_(LogSeverity::Regular)
|
|
, watch_(&UtcWatch::service())
|
|
{
|
|
}
|
|
|
|
/// Cleans everything up.
|
|
~FileLoggerSettings()
|
|
{
|
|
}
|
|
|
|
/// Log file name.
|
|
///
|
|
/// Ignored if logging is disabled.
|
|
const std::string& filename() const
|
|
{
|
|
return filename_;
|
|
}
|
|
|
|
/// Updates log file name.
|
|
///
|
|
/// Ignored if logging is disabled.
|
|
void filename(const std::string& value)
|
|
{
|
|
filename_ = value;
|
|
}
|
|
|
|
/// Log file size limit (in bytes).
|
|
///
|
|
/// Handler detaches logged data into separate
|
|
/// file upon reaching given size limit.
|
|
///
|
|
/// @note Default value is '2145386496'.
|
|
UInt64 fileSizeLimit() const
|
|
{
|
|
return fileSizeLimit_;
|
|
}
|
|
|
|
/// Sets logFileSizeLimit. @see logFileSizeLimit.
|
|
void fileSizeLimit(UInt64 value)
|
|
{
|
|
fileSizeLimit_ = value;
|
|
}
|
|
|
|
/// Specifies whether the logger should output events
|
|
/// and which of events should be put into the log.
|
|
///
|
|
/// @note The default value is LogEntrySeverity::Regular.
|
|
LogSeverity::Enum severityLevel() const
|
|
{
|
|
return severity_;
|
|
}
|
|
|
|
/// Specifies whether logger should output its events
|
|
/// and which of events should be put into the log.
|
|
void severityLevel(LogSeverity::Enum value)
|
|
{
|
|
severity_ = value;
|
|
}
|
|
|
|
/// Watch service used by logger while
|
|
/// assigning timestamps to log entries.
|
|
WatchService& watch() const
|
|
{
|
|
return *watch_;
|
|
}
|
|
|
|
/// Watch service used by logger while
|
|
/// assigning timestamps to log entries.
|
|
void watch(WatchService& watch)
|
|
{
|
|
watch_ = &watch;
|
|
}
|
|
};
|
|
|
|
/// Makes filename for log file for the given channel.
|
|
ONIXS_CMEMDH_EXPORTED
|
|
std::string
|
|
makeLogFilename(UInt32);
|
|
|
|
/// Implements logging services to put logged data into a
|
|
/// regular file. Provides additional facilities like splitting
|
|
/// logged data into chunks not exceeding specified size limit.
|
|
ONIXS_CMEMDH_EXPORTED_CLASS FileLogger : public Logger
|
|
{
|
|
// File logger machinery implementation.
|
|
|
|
ONIXS_CMEMDH_LTWT_CLASS_DECL(Workhorse);
|
|
Workhorse* workhorse_;
|
|
|
|
public:
|
|
/// Initializes logger according to given settings.
|
|
FileLogger(const FileLoggerSettings&);
|
|
|
|
/// Disposes logging machinery.
|
|
virtual ~FileLogger();
|
|
|
|
/// Adds new entry into the log.
|
|
virtual LogEntry* addEntry(LogSeverity::Enum);
|
|
|
|
/// Backs up current log and starts recording new chunk.
|
|
virtual void backup();
|
|
};
|
|
|
|
ONIXS_CMEMDH_NAMESPACE_END
|