OnixS C++ CME MDP Premium Market Data Handler  5.8.9
API Documentation
FileLogger.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
23 #include <OnixS/CME/MDH/String.h>
24 #include <OnixS/CME/MDH/Integral.h>
25 
26 #include <OnixS/CME/MDH/Logger.h>
27 #include <OnixS/CME/MDH/Watch.h>
28 
30 
31 /// Base parameters affecting synchronous logging services.
33 {
34 public:
35  /// Initializes parameters with default values.
37  : filename_()
38  , fileSizeLimit_(2145386496)
39  , severity_(LogSeverity::Regular)
40  , watch_(&UtcWatch::service())
41  {
42  }
43 
44  /// Cleans everything up.
46 
47  /// Log file name.
48  ///
49  /// Ignored if logging is disabled.
50  const std::string& filename() const
51  {
52  return filename_;
53  }
54 
55  /// Updates log file name.
56  ///
57  /// Ignored if logging is disabled.
58  void filename(const std::string& value)
59  {
60  filename_ = value;
61  }
62 
63  /// Log file size limit (in bytes).
64  ///
65  /// Handler detaches logged data into separate
66  /// file upon reaching given size limit.
67  ///
68  /// @note Default value is '2145386496'.
70  {
71  return fileSizeLimit_;
72  }
73 
74  /// Sets logFileSizeLimit. @see logFileSizeLimit.
76  {
77  fileSizeLimit_ = value;
78  }
79 
80  /// Specifies whether the logger should output events
81  /// and which of events should be put into the log.
82  ///
83  /// @note The default value is LogEntrySeverity::Regular.
85  {
86  return severity_;
87  }
88 
89  /// Specifies whether logger should output its events
90  /// and which of events should be put into the log.
92  {
93  severity_ = value;
94  }
95 
96  /// Watch service used by logger while
97  /// assigning timestamps to log entries.
99  {
100  return *watch_;
101  }
102 
103  /// Watch service used by logger while
104  /// assigning timestamps to log entries.
105  void watch(WatchService& watch)
106  {
107  watch_ = &watch;
108  }
109 
110 private:
111  std::string filename_;
112  UInt64 fileSizeLimit_;
113 
114  LogSeverity::Enum severity_;
115 
116  WatchService* watch_;
117 };
118 
119 /// Makes filename for log file for the given channel.
121 std::string makeLogFilename(UInt32);
122 
124 
125 /// Collection of events raised by FileLogger during its life time.
127 {
128  /// Invoked by FileLogger in case of issue.
129  ///
130  /// FileLogger may experience issues like inability to
131  /// add a new entry due to insufficient disk space. Once
132  /// occurred, issue is reported through given callback.
133  virtual void onFileLoggerIssue(const FileLogger&, const Char*) {}
134 };
135 
136 /// Implements logging services to put logged data into a
137 /// regular file. Provides additional facilities like splitting
138 /// logged data into chunks not exceeding specified size limit.
140 {
141 public:
142  /// Initializes logger according to given settings.
144 
145  /// Disposes logging machinery.
147 
148  /// Configuration of given logger instance.
149  const FileLoggerSettings& settings() const;
150 
151  /// Basic information on the implementation
152  /// of the logging services.
153  void info(std::string&) ONIXS_CMEMDH_OVERRIDE;
154 
155  /// Adds a new entry into the log.
156  ///
157  /// Returns instance for further fulfill or ONIXS_CMEMDH_NULLPTR if
158  /// given severity is lower than defined by settings
159  /// at the moment of instance construction.
161 
162  /// Rolls over current log and starts recording a new chunk.
163  ///
164  /// Detached data is stored into a file whose name is
165  /// suffixed with a timestamp taken at the moment of detach.
166  /// Timestamp is taken using watch service associated with
167  /// the logger using its settings.
168  ///
169  /// @return Name of file containing detached data.
170  std::string rollover();
171 
172 private:
173  // File logger machinery implementation.
174  ONIXS_CMEMDH_LTWT_CLASS_DECL(Workhorse);
175 
176  Workhorse* workhorse_;
177 };
178 
Collection of events raised by FileLogger during its life time.
Definition: FileLogger.h:126
virtual void onFileLoggerIssue(const FileLogger &, const Char *)
Invoked by FileLogger in case of issue.
Definition: FileLogger.h:133
#define ONIXS_CMEMDH_OVERRIDE
Definition: Compiler.h:165
UInt32 UInt32
uInt32.
Definition: Fields.h:192
#define ONIXS_CMEMDH_NULLPTR
Definition: Compiler.h:167
Base parameters affecting synchronous logging services.
Definition: FileLogger.h:32
Defines severity levels for log entries.
Definition: Logger.h:29
FileLoggerSettings()
Initializes parameters with default values.
Definition: FileLogger.h:36
#define ONIXS_CMEMDH_EXPORTED_CLASS_DECL(typeName)
Definition: Bootstrap.h:35
Abstract watch service.
Definition: Watch.h:29
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
Abstraction of log entry in logging services.
Definition: Logger.h:121
char Char
Character type alias.
Definition: String.h:36
const std::string & filename() const
Log file name.
Definition: FileLogger.h:50
WatchService & watch() const
Watch service used by logger while assigning timestamps to log entries.
Definition: FileLogger.h:98
UInt64 UInt64
uInt64.
Definition: Fields.h:195
bool value(Number &number, const MultiContainer &container, Tag tag)
Finds a tag-value entry in the given collection by the given tag and returns its value component tran...
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:67
std::string makeLogFilename(UInt32)
Makes filename for log file for the given channel.
LogSeverity::Enum severityLevel() const
Specifies whether the logger should output events and which of events should be put into the log...
Definition: FileLogger.h:84
#define ONIXS_CMEMDH_EXPORTED
Definition: Compiler.h:160
#define ONIXS_CMEMDH_LTWT_CLASS_DECL(name)
Definition: Bootstrap.h:48
Enum
Log alternates.
Definition: Logger.h:35
void severityLevel(LogSeverity::Enum value)
Specifies whether logger should output its events and which of events should be put into the log...
Definition: FileLogger.h:91
Abstraction of logger.
Definition: Logger.h:155
~FileLoggerSettings()
Cleans everything up.
Definition: FileLogger.h:45
void watch(WatchService &watch)
Watch service used by logger while assigning timestamps to log entries.
Definition: FileLogger.h:105
void filename(const std::string &value)
Updates log file name.
Definition: FileLogger.h:58
void fileSizeLimit(UInt64 value)
Sets logFileSizeLimit.
Definition: FileLogger.h:75
UInt64 fileSizeLimit() const
Log file size limit (in bytes).
Definition: FileLogger.h:69
Implements logging services to put logged data into a regular file.
Definition: FileLogger.h:139
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:68