OnixS C++ CME Market Data Handler  5.4.0
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  std::string filename_;
35  UInt64 fileSizeLimit_;
36 
37  LogSeverity::Enum severity_;
38 
39  WatchService* watch_;
40 
41 public:
42  /// Initializes parameters with default values.
44  : filename_()
45  , fileSizeLimit_(2145386496)
46  , severity_(LogSeverity::Regular)
47  , watch_(&UtcWatch::service())
48  {
49  }
50 
51  /// Cleans everything up.
53  {
54  }
55 
56  /// Log file name.
57  ///
58  /// Ignored if logging is disabled.
59  const std::string& filename() const
60  {
61  return filename_;
62  }
63 
64  /// Updates log file name.
65  ///
66  /// Ignored if logging is disabled.
67  void filename(const std::string& value)
68  {
69  filename_ = value;
70  }
71 
72  /// Log file size limit (in bytes).
73  ///
74  /// Handler detaches logged data into separate
75  /// file upon reaching given size limit.
76  ///
77  /// @note Default value is '2145386496'.
79  {
80  return fileSizeLimit_;
81  }
82 
83  /// Sets logFileSizeLimit. @see logFileSizeLimit.
85  {
86  fileSizeLimit_ = value;
87  }
88 
89  /// Specifies whether the logger should output events
90  /// and which of events should be put into the log.
91  ///
92  /// @note The default value is LogEntrySeverity::Regular.
94  {
95  return severity_;
96  }
97 
98  /// Specifies whether logger should output its events
99  /// and which of events should be put into the log.
101  {
102  severity_ = value;
103  }
104 
105  /// Watch service used by logger while
106  /// assigning timestamps to log entries.
108  {
109  return *watch_;
110  }
111 
112  /// Watch service used by logger while
113  /// assigning timestamps to log entries.
114  void watch(WatchService& watch)
115  {
116  watch_ = &watch;
117  }
118 };
119 
120 /// Makes filename for log file for the given channel.
121 ONIXS_CMEMDH_EXPORTED
122 std::string
124 
126 
127 /// Collection of events raised by FileLogger during its life time.
129 {
130  /// Invoked by FileLogger in case of issue.
131  ///
132  /// FileLogger may experience issues like inability to
133  /// add a new entry due to insufficient disk space. Once
134  /// occurred, issue is reported through given callback.
135  virtual
136  void
138  const FileLogger&,
139  const Char*)
140  {
141  }
142 };
143 
144 /// Implements logging services to put logged data into a
145 /// regular file. Provides additional facilities like splitting
146 /// logged data into chunks not exceeding specified size limit.
148 {
149  // File logger machinery implementation.
150  ONIXS_CMEMDH_LTWT_CLASS_DECL(Workhorse);
151 
152  Workhorse* workhorse_;
153 
154 public:
155  /// Initializes logger according to given settings.
156  FileLogger(
157  const FileLoggerSettings&,
158  FileLoggerListener* = NULL);
159 
160  /// Disposes logging machinery.
161  ~FileLogger();
162 
163  /// Configuration of given logger instance.
164  const
166  settings() const;
167 
168  /// Basic information on the implementation
169  /// of the logging services.
170  void
171  info(
172  std::string&);
173 
174  /// Adds a new entry into the log.
175  ///
176  /// Returns instance for further fulfill or NULL if
177  /// given severity is lower than defined by settings
178  /// at the moment of instance construction.
179  LogEntry*
180  addEntry(
182 
183  /// Rolls over current log and starts recording a new chunk.
184  ///
185  /// Detached data is stored into a file whose name is
186  /// suffixed with a timestamp taken at the moment of detach.
187  /// Timestamp is taken using watch service associated with
188  /// the logger using its settings.
189  ///
190  /// @return Name of file containing detached data.
191  std::string rollover();
192 };
193 
Collection of events raised by FileLogger during its life time.
Definition: FileLogger.h:128
#define ONIXS_CMEMDH_LTWT_CLASS
Definition: Bootstrap.h:94
virtual void onFileLoggerIssue(const FileLogger &, const Char *)
Definition: FileLogger.h:137
UInt32 UInt32
uInt32.
Definition: Fields.h:247
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:43
#define ONIXS_CMEMDH_EXPORTED_CLASS_DECL(typeName)
Definition: Bootstrap.h:46
Abstract watch service.
Definition: Watch.h:29
Abstraction of log entry in logging services.
Definition: Logger.h:141
char Char
Character type alias.
Definition: String.h:36
const std::string & filename() const
Definition: FileLogger.h:59
WatchService & watch() const
Definition: FileLogger.h:107
UInt64 UInt64
uInt64.
Definition: Fields.h:251
bool value(Number &number, const MultiContainer &container, Tag tag)
#define ONIXS_CMEMDH_EXPORTED_CLASS
Definition: Bootstrap.h:54
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:152
LogSeverity::Enum severityLevel() const
Definition: FileLogger.h:93
#define ONIXS_CMEMDH_LTWT_CLASS_DECL(name)
Definition: Bootstrap.h:106
Enum
Log alternates.
Definition: Logger.h:35
void severityLevel(LogSeverity::Enum value)
Definition: FileLogger.h:100
ONIXS_CMEMDH_EXPORTED std::string makeLogFilename(UInt32)
Makes filename for log file for the given channel.
Abstraction of logger.
Definition: Logger.h:179
~FileLoggerSettings()
Cleans everything up.
Definition: FileLogger.h:52
void watch(WatchService &watch)
Definition: FileLogger.h:114
#define ONIXS_CMEMDH_EXPORTED_STRUCT
Definition: Bootstrap.h:58
void filename(const std::string &value)
Definition: FileLogger.h:67
void fileSizeLimit(UInt64 value)
Sets logFileSizeLimit.
Definition: FileLogger.h:84
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:156