BDE 4.39.x Production Release
Loading...
Searching...
No Matches
ball_fileobserver.h
Go to the documentation of this file.
1/// @file ball_fileobserver.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// ball_fileobserver.h -*-C++-*-
8#ifndef INCLUDED_BALL_FILEOBSERVER
9#define INCLUDED_BALL_FILEOBSERVER
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup ball_fileobserver ball_fileobserver
15/// @brief Provide a thread-safe observer that logs to a file and to `stdout`.
16/// @addtogroup bal
17/// @{
18/// @addtogroup ball
19/// @{
20/// @addtogroup ball_fileobserver
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#ball_fileobserver-purpose"> Purpose</a>
25/// * <a href="#ball_fileobserver-classes"> Classes </a>
26/// * <a href="#ball_fileobserver-description"> Description </a>
27/// * <a href="#ball_fileobserver-file-observer-configuration-synopsis"> File Observer Configuration Synopsis </a>
28/// * <a href="#ball_fileobserver-log-record-formatting"> Log Record Formatting </a>
29/// * <a href="#ball_fileobserver-scheme-based-format-specifications"> Scheme-Based Format Specifications (Recommended) </a>
30/// * <a href="#ball_fileobserver-legacy-format-specifications"> Legacy Format Specifications </a>
31/// * <a href="#ball_fileobserver-legacy-api-setlogformat"> Legacy API: setLogFormat </a>
32/// * <a href="#ball_fileobserver-interaction-with-enablestdoutloggingprefix-disablestdoutloggingprefix"> Interaction with enableStdoutLoggingPrefix & disableStdoutLoggingPrefix </a>
33/// * <a href="#ball_fileobserver-log-record-timestamps"> Log Record Timestamps </a>
34/// * <a href="#ball_fileobserver-local-time-offset-calculations"> Local Time Offset Calculations </a>
35/// * <a href="#ball_fileobserver-log-filename-patterns"> Log Filename Patterns </a>
36/// * <a href="#ball_fileobserver-log-file-rotation"> Log File Rotation </a>
37/// * <a href="#ball_fileobserver-file-rotation-conditions"> File Rotation Conditions </a>
38/// * <a href="#ball_fileobserver-rotated-file-naming"> Rotated File Naming </a>
39/// * <a href="#ball_fileobserver-thread-safety"> Thread Safety </a>
40/// * <a href="#ball_fileobserver-usage"> Usage </a>
41/// * <a href="#ball_fileobserver-example-basic-usage"> Example: Basic Usage </a>
42///
43/// # Purpose {#ball_fileobserver-purpose}
44/// Provide a thread-safe observer that logs to a file and to `stdout`.
45///
46/// # Classes {#ball_fileobserver-classes}
47///
48/// - ball::FileObserver: observer that writes log records to a file and `stdout`
49///
50/// @see ball_record, ball_context, ball_observer, ball_fileobserver2
51///
52/// # Description {#ball_fileobserver-description}
53/// This component provides a concrete implementation of the
54/// `ball::Observer` protocol, `ball::FileObserver`, for publishing log records
55/// to `stdout` and, optionally, to a user-specified file. The following
56/// inheritance hierarchy diagram shows the classes involved and their methods:
57/// @code
58/// ,------------------.
59/// ( ball::FileObserver )
60/// `------------------'
61/// | ctor
62/// | disableFileLogging
63/// | disableTimeIntervalRotation
64/// | disableSizeRotation
65/// | disableStdoutLoggingPrefix
66/// | disablePublishInLocalTime
67/// | enableFileLogging
68/// | enableStdoutLoggingPrefix
69/// | enablePublishInLocalTime
70/// | forceRotation
71/// | rotateOnSize
72/// | rotateOnTimeInterval
73/// | setFileLogFormat
74/// | setLogFormat
75/// | setLogFormats
76/// | setOnFileRotationCallback
77/// | setStdoutLogFormat
78/// | setStdoutThreshold
79/// | suppressUniqueFileNameOnRotation
80/// | getFileLogFormat
81/// | getLogFormat
82/// | getStdoutLogFormat
83/// | isFileLoggingEnabled
84/// | isStdoutLoggingPrefixEnabled
85/// | isPublishInLocalTimeEnabled
86/// | isSuppressUniqueFileNameOnRotation
87/// | rotationLifetime
88/// | rotationSize
89/// | stdoutThreshold
90/// V
91/// ,--------------.
92/// ( ball::Observer )
93/// `--------------'
94/// dtor
95/// publish
96/// releaseRecords
97/// @endcode
98/// A `ball::FileObserver` object processes the log records received through its
99/// `publish` method by writing them to `stdout` and, if so configured, to a
100/// user-specified file. The format of published log records is
101/// user-configurable for both destinations, `stdout` and file (see {Log Record
102/// Formatting} below). Although logging to a file is initially disabled
103/// following construction, the most common use-case for `ball::FileObserver` is
104/// to also log to a file, enabled by calling the `enableFileLogging` method.
105/// In addition, a file observer may be configured to perform automatic log file
106/// rotation (see {Log File Rotation} below).
107///
108/// ## File Observer Configuration Synopsis {#ball_fileobserver-file-observer-configuration-synopsis}
109///
110///
111/// `ball::FileObserver` offers several constructor arguments and manipulators
112/// that may be used to configure various aspects of a file observer object.
113/// These are summarized in the following tables along with the accessors that
114/// can be used to query the current state of the configuration. Further
115/// details are provided in the following sections and the function-level
116/// documentation.
117/// @code
118/// +-----------------------+-----------------------+
119/// | Aspect | Constructor Arguments |
120/// +=======================+=======================+
121/// | Log Record Timestamps | publishInLocalTime |
122/// +-----------------------+-----------------------+
123/// | `stdout` Logging | stdoutThreshold |
124/// +-----------------------+-----------------------+
125///
126/// +-------------+------------------------------------+
127/// | Aspect | Related Methods |
128/// +=============+====================================+
129/// | Log Record | setLogFormat |
130/// | Formatting | enableStdoutLoggingPrefix |
131/// | | disableStdoutLoggingPrefix |
132/// | | getLogFormat |
133/// | | isStdoutLoggingPrefixEnabled |
134/// +-------------+------------------------------------+
135/// | Log Record | enablePublishInLocalTime |
136/// | Timestamps | disablePublishInLocalTime |
137/// | | isPublishInLocalTimeEnabled |
138/// | | |
139/// +-------------+------------------------------------+
140/// | File | enableFileLogging |
141/// | Logging | disableFileLogging |
142/// | | isFileLoggingEnabled |
143/// | | |
144/// +-------------+------------------------------------+
145/// | `stdout` | setStdoutThreshold |
146/// | Logging | enableStdoutLoggingPrefix |
147/// | | disableStdoutLoggingPrefix |
148/// | | stdoutThreshold |
149/// | | isStdoutLoggingPrefixEnabled |
150/// +-------------+------------------------------------+
151/// | Log File | rotateOnSize |
152/// | Rotation | rotateOnTimeInterval |
153/// | | disableSizeRotation |
154/// | | disableTimeIntervalRotation |
155/// | | setOnFileRotationCallback |
156/// | | suppressUniqueFileNameOnRotation |
157/// | | rotationSize |
158/// | | rotationLifetime |
159/// | | isSuppressUniqueFileNameOnRotation |
160/// +-------------+------------------------------------+
161/// @endcode
162/// In general, a `ball::FileObserver` object can be dynamically configured
163/// throughout its lifetime (in particular, before or after being registered
164/// with a logger manager). However, note that for `ball::FileObserver`,
165/// configuration changes that affect how records are logged (e.g.,
166/// `enablePublishInLocalTime` and `disablePublishInLocalTime`) impact only
167/// those records that are published subsequent to making the configuration
168/// change.
169///
170/// ## Log Record Formatting {#ball_fileobserver-log-record-formatting}
171///
172///
173/// By default, the output format of published log records, whether written to
174/// `stdout` or to a user-specified file, is:
175/// @code
176/// DATE_TIME PID:THREAD-ID SEVERITY FILE:LINE CATEGORY MESSAGE USER-FIELDS
177/// @endcode
178/// where `DATE` and `TIME` are of the form `DDMonYYYY` and `HH:MM:SS.mmm`,
179/// respectively (`Mon` being the 3-letter abbreviation for the month). For
180/// example, a log record will have the following appearance when the default
181/// format is in effect (assuming that no user-defined fields are present):
182/// @code
183/// 18MAY2005_18:58:12.076 7959:1 WARN ball_fileobserver.t.cpp:404 TEST hello!
184/// @endcode
185/// The default format for records published to `stdout` (only) can be shortened
186/// by calling `disableStdoutLoggingPrefix`. This method has the effect of
187/// reducing the above example message to the following when output to `stdout`:
188/// @code
189/// WARN ball_fileobserver.t.cpp:404 TEST hello!
190/// @endcode
191/// For additional flexibility, the `setFileLogFormat` and `setStdoutLogFormat`
192/// methods can be called to independently configure the format of published
193/// records to a file and to `stdout`, respectively. The format specifications
194/// can be either scheme-tagged (recommended) or legacy `printf`-style format
195/// strings that results in a `RecordStringFormatter` being used.
196///
197/// ### Scheme-Based Format Specifications (Recommended) {#ball_fileobserver-scheme-based-format-specifications}
198///
199///
200/// The recommended way to specify log record formats is using URI-like
201/// scheme-tagged format configuration strings. A scheme-tagged format string
202/// begins with a scheme identifier followed by `://` and then a
203/// scheme-specific format specification:
204/// @code
205/// <scheme>://<format-specification>
206/// @endcode
207/// The scheme determines which formatter will be used and the syntax of the
208/// format specification. The following schemes are currently supported: text,
209/// json, qjson. See [Scheme-Based Formatters](@ref ball-scheme-based-formatters)
210/// for more details of the supported schemes and their accompanying format
211/// specification syntaxes.
212///
213/// For example, to log records to a file in JSON format with printf-style
214/// format specification, and to `stdout` using text format with ISO 8601
215/// timestamps:
216/// @code
217/// fileObserver.setFileLogFormat("qjson://%d %p:%t %s %f:%l %c %m");
218/// fileObserver.setStdoutLogFormat("text://\n%I %p:%t %s %f:%l %c %m\n");
219/// @endcode
220/// Note that both `text://` and `qjson://` schemes support `printf`-style `%`
221/// specifications in their format strings, though with different output
222/// structures (plain text vs. JSON).
223///
224/// ### Legacy Format Specifications {#ball_fileobserver-legacy-format-specifications}
225///
226///
227/// For backward compatibility, format specifications that do not begin with a
228/// scheme tag are treated as legacy `printf`-style format strings. Such
229/// specifications are implicitly treated as if they had a `text://` prefix
230/// and use `ball::RecordStringFormatter`. For example, the following two
231/// calls are equivalent:
232/// @code
233/// fileObserver.setFileLogFormat("%d %p:%t %s %f:%l %c %m %a\n");
234/// fileObserver.setFileLogFormat("text://%d %p:%t %s %f:%l %c %m %a\n");
235/// @endcode
236/// These `%`-prefixed conversion specifications are defined in
237/// @ref ball_recordstringformatter .
238///
239/// ### Legacy API: setLogFormat {#ball_fileobserver-legacy-api-setlogformat}
240///
241///
242/// The `setLogFormat` method sets both file and stdout formats at once.
243/// Using `setFileLogFormat` and `setStdoutLogFormat` is preferred to set
244/// formats independently for file and `stdout` output:
245/// @code
246/// // Legacy:
247/// fileObserver.setLogFormat(fileFormat, stdoutFormat);
248///
249/// // Preferred:
250/// fileObserver.setFileLogFormat(fileFormat);
251/// fileObserver.setStdoutLogFormat(stdoutFormat);
252/// @endcode
253///
254/// ### Interaction with enableStdoutLoggingPrefix & disableStdoutLoggingPrefix {#ball_fileobserver-interaction-with-enablestdoutloggingprefix-disablestdoutloggingprefix}
255///
256///
257/// When a format is set using `setLogFormat`, calling
258/// `disableStdoutLoggingPrefix` will change the stdout format to the default
259/// short format (i.e., "\n%s %f:%l %c %m %u\n"), regardless of whether the
260/// original format was specified as a `printf`-style format string or a
261/// scheme-based formatter. If `enableStdoutLoggingPrefix` is subsequently
262/// called, the format specified in the most recent call to `setLogFormat` will
263/// be reinstated, preserving the original formatter type (string-based or
264/// scheme-based).
265///
266/// ## Log Record Timestamps {#ball_fileobserver-log-record-timestamps}
267///
268///
269/// By default, the timestamp attributes of published records are written in UTC
270/// time (unless `true` is supplied for the optional `publishInLocalTime`
271/// constructor flag). To write timestamps in local time instead, call the
272/// `enablePublishInLocalTime` method. Note that the local time offset is
273/// calculated using the UTC timestamp of each record. To revert to UTC time,
274/// call the `disablePublishInLocalTime` method. Whether UTC time or local time
275/// is in effect can be queried via `isPublishInLocalTimeEnabled`.
276///
277/// ### Local Time Offset Calculations {#ball_fileobserver-local-time-offset-calculations}
278///
279///
280/// The calculation of the local time offset adds some overhead to the
281/// publication of each log record. If this overhead is an issue, it can be
282/// mitigated by installing a high-performance local-time offset callback for
283/// `bdlt::CurrentTime` in `main`. See @ref bsls_systemtime for the details of
284/// installing such a callback and see @ref baltzo_localtimeoffsetutil for an
285/// example facility. Note that such callbacks can improve performance for all
286/// users of `bdlt::CurrentTime`, not just the `ball` logger.
287///
288/// ## Log Filename Patterns {#ball_fileobserver-log-filename-patterns}
289///
290///
291/// The `enableFileLogging` method supports the use of `%`-escape sequences to
292/// specify log filenames. The recognized sequences are as follows:
293/// @code
294/// %Y - current year (4 digits with leading zeros)
295/// %M - current month (2 digits with leading zeros)
296/// %D - current day (2 digits with leading zeros)
297/// %h - current hour (2 digits with leading zeros)
298/// %m - current minute (2 digits with leading zeros)
299/// %s - current second (2 digits with leading zeros)
300/// %T - current datetime, equivalent to "%Y%M%D_%h%m%s"
301/// %p - process ID
302/// @endcode
303/// The date and time elements of the derived filename are based on the time
304/// when the log file is created. Furthermore, these elements are based on
305/// either UTC time or local time depending on the value returned by
306/// `isPublishInLocalTimeEnabled`. (See {Log Record Timestamps} for the
307/// similarity with the treatment of record timestamps.)
308///
309/// For example, a log filename pattern of "task.log.%Y%M%D_%h%m%s" will yield
310/// the filename `task.log.20110501_123000` if the file is created on
311/// 01-May-2011 at 12:30:00 local time (assuming `enablePublishInLocalTime` was
312/// called).
313///
314/// ## Log File Rotation {#ball_fileobserver-log-file-rotation}
315///
316///
317/// A `ball::FileObserver` may be configured to perform automatic rotation of
318/// log files based on simple file rotation conditions (or rules).
319///
320/// ### File Rotation Conditions {#ball_fileobserver-file-rotation-conditions}
321///
322///
323/// Rotation rules may be established based on the size of the log file (i.e., a
324/// "rotation-on-size" rule), and a periodic time interval (i.e., a
325/// "rotation-on-time-interval" rule). These rules are independently enabled by
326/// the `rotateOnSize` and `rotateOnTimeInterval` methods, respectively. If
327/// both rules are in effect, log file rotation is performed whenever either
328/// rule applies.
329///
330/// ### Rotated File Naming {#ball_fileobserver-rotated-file-naming}
331///
332///
333/// When a log file is rotated, a new filename is generated using the pattern
334/// supplied to `enableFileLogging`. If the file having the new name does not
335/// exist, the current log file is closed, and the logging continues to the new
336/// file.
337///
338/// If the file having the new name already exists, then the behavior of the
339/// file rotation is further controlled by the flag set with
340/// `suppressUniqueFileNameOnRotation`:
341///
342/// * `suppressUniqueFileNameOnRotation(false)` (*default* behavior)
343/// The current log filename is renamed by appending a timestamp in the form
344/// ".%Y%M%D_%h%m%s" where the timestamp indicates when the file being
345/// rotated was last opened (the time of either the last file rotation or the
346/// last call to `enableFileLogging`, whichever is most recent). As with the
347/// timestamps of logged records, the timestamps appended to log filenames
348/// upon rotation will be in UTC time or local time depending on the value
349/// returned by `isPublishInLocalTimeEnabled`.
350/// * `suppressUniqueFileNameOnRotation(true)`
351/// The logging continues to the *current* log file, effectively suppressing
352/// log filename rotation. This may happen when the log file pattern does
353/// not contain %-escape sequences indicating a time period, or the rotation
354/// interval is less than the time period encoded by %-escape sequences. In
355/// order to rotate log files in this mode, the log file pattern MUST contain
356/// %-escape sequences that specify date and (optionally) time. For example,
357/// the log filename pattern "app_%Y%M%D.log" will produce a single log file
358/// per calendar day (assuming, the rotation on time is enabled and the
359/// rotation happens at least once a day).
360///
361/// The two tables below illustrate the names of old and new log files when a
362/// file rotation occurs. We assume that the log file is rotated on 2011-May-21
363/// at 12:29:59 local time and that the last rotation occurred at 12:30:00 on
364/// the previous day. We further assume that `enablePublishInLocalTime` was
365/// called, so that all date and time elements are rendered in local time.
366///
367/// The first table shows the name change (if any) of the (old) log file being
368/// rotated when the flag controlled by `suppressUniqueFileNameOnRotation`
369/// is set to `false`:
370/// @code
371/// Disabled: `suppressUniqueFileNameOnRotation`
372///
373/// For brevity:
374/// <TS1> = 20210520_123000
375/// <TS2> = 20210521_122959 (aka next day, about the same time)
376///
377/// +----------------+-----------------+----------------+----------------------
378/// | Pattern | Filename Before | Filename After | Rotated Filename
379/// | | Rotation | Rotation |
380/// +----------------+-----------------+----------------+----------------------
381/// | "a.log" | a.log | a.log | a.log.<TS1>
382/// | "a.log.%T" | a.log.<TS1> | a.log.<TS2> | a.log.<TS1>
383/// | "a.log.%Y%M" | a.log.202105 | a.log.202105 | a.log.202105.<TS1>
384/// | "a.log.%Y%M%D" | a.log.20210520 | a.log.20110521 | a.log.20210520
385/// +----------------+-----------------+----------------+----------------------
386/// @endcode
387/// Note that upon rotation a timestamp was appended to the name of the rotated
388/// file when the log pattern does not contain %-escape sequences indicating a
389/// time period ("a.log"), or the rotation period (in our case, one day) is less
390/// than the time period encoded in the pattern (in case of "a.log.%Y%M" the
391/// period is one month).
392///
393/// The next table shows the rotated name when the flag controlled by
394/// `suppressUniqueFileNameOnRotation` is set to `true`, and (possibly new) name
395/// of the (new) log file following rotation:
396/// @code
397/// Enabled: `suppressUniqueFileNameOnRotation`
398///
399/// +----------------+-----------------+----------------+----------------------
400/// | Pattern | Filename Before | Filename After | Rotated Filename
401/// | | Rotation | Rotation |
402/// +----------------+-----------------+----------------+----------------------
403/// | "a.log" | a.log | a.log | none
404/// | "a.log.%T" | a.log.<TS1> | a.log.<TS2> | a.log.<TS1>
405/// | "a.log.%Y%M" | a.log.202105 | a.log.202105 | none
406/// | "a.log.%Y%M%D" | a.log.20210520 | a.log.20110521 | a.log.20210520
407/// +----------------+-----------------+----------------+----------------------
408/// @endcode
409/// Note that the original filename is reused when the log pattern does not
410/// contain %-escape sequences indicating a time period ("a.log"), or the
411/// rotation period (in our case, one day) is less than the time period encoded
412/// in the pattern (in case of "a.log.%Y%M" the period is one month).
413///
414/// Also note, that in any cases, when the log pattern includes "%T", or encodes
415/// a time period that coincides the rotation period (in case of "a.log.%Y%M%D"
416/// the period is one day), then a unique name on each rotation is produced with
417/// the (local) time at which file rotation occurred embedded in the filename.
418///
419/// ## Thread Safety {#ball_fileobserver-thread-safety}
420///
421///
422/// All methods of `ball::FileObserver` are thread-safe, and can be called
423/// concurrently by multiple threads.
424///
425/// ## Usage {#ball_fileobserver-usage}
426///
427///
428/// This section illustrates intended use of this component.
429///
430/// ### Example: Basic Usage {#ball_fileobserver-example-basic-usage}
431///
432///
433/// First, we create a `ball::LoggerManagerConfiguration` object, `lmConfig`,
434/// and set the logging "pass-through" level -- the level at which log records
435/// are published to registered observers -- to `DEBUG`:
436/// @code
437/// int main()
438/// {
439/// ball::LoggerManagerConfiguration lmConfig;
440/// lmConfig.setDefaultThresholdLevelsIfValid(ball::Severity::e_DEBUG);
441/// @endcode
442/// Next, create a `ball::LoggerManagerScopedGuard` object whose constructor
443/// takes the configuration object just created. The guard will initialize the
444/// logger manager singleton on creation and destroy the singleton upon
445/// destruction. This guarantees that any resources used by the logger manager
446/// will be properly released when they are not needed:
447/// @code
448/// ball::LoggerManagerScopedGuard guard(lmConfig);
449/// ball::LoggerManager& manager = ball::LoggerManager::singleton();
450/// @endcode
451/// Next, we create a `ball::FileObserver` object and register it with the
452/// `ball` logging system;
453/// @code
454/// bsl::shared_ptr<ball::FileObserver> observer =
455/// bsl::make_shared<ball::FileObserver>();
456/// int rc = manager.registerObserver(observer, "default");
457/// ASSERT(0 == rc);
458/// @endcode
459/// The default format for outputting log records can be changed by calling the
460/// `setFileLogFormat` and `setStdoutLogFormat` methods. The statements below
461/// output record timestamps in ISO 8601 format to the log file and in
462/// `bdlt`-style (default) format to `stdout`, where timestamps are output with
463/// millisecond precision in both cases:
464/// @code
465/// observer->setFileLogFormat("%I %p:%t %s %f:%l %c %m\n");
466/// observer->setStdoutLogFormat("%d %p:%t %s %f:%l %c %m\n");
467/// @endcode
468/// Note that both of the above format specifications omit user fields (`"%u"`)
469/// in the output. Also note that, unlike the default, this format does not
470/// emit a blank line between consecutive log messages.
471///
472/// Henceforth, all messages that are published by the logging system will be
473/// transmitted to the `publish` method of `observer`. By default, only the
474/// messages with a `e_WARN`, `e_ERROR`, or `e_FATAL` severity will be logged to
475/// `stdout`:
476/// @code
477/// BALL_LOG_SET_CATEGORY("main")
478/// BALL_LOG_INFO << "Will not be published on 'stdout'.";
479/// BALL_LOG_WARN << "This warning *will* be published on 'stdout'.";
480/// @endcode
481/// This default can be changed by specifying an optional argument to the
482/// `ball::FileObserver` constructor or by calling the `setStdoutThreshold`
483/// method:
484/// @code
485/// observer->setStdoutThreshold(ball::Severity::e_INFO);
486///
487/// BALL_LOG_DEBUG << "This debug message is not published on 'stdout'.";
488/// BALL_LOG_INFO << "This info message *will* be published on 'stdout'.";
489/// BALL_LOG_WARN << "This warning will be published on 'stdout'.";
490/// @endcode
491/// The user can log all messages to a specified file and specify rotation rules
492/// based on the size of the log file or its lifetime:
493/// @code
494/// // Create and log records to a file named "/var/log/task/task.log".
495/// observer->enableFileLogging("/var/log/task/task.log");
496///
497/// // Disable 'stdout' logging.
498/// observer->setStdoutThreshold(ball::Severity::e_OFF);
499///
500/// // Rotate the file when its size becomes greater than or equal to 256
501/// // megabytes.
502/// observer->rotateOnSize(1024 * 256);
503///
504/// // Rotate the file every 24 hours.
505/// observer->rotateOnTimeInterval(bdlt::DatetimeInterval(1));
506/// @endcode
507/// Note that in this configuration the user may end up with multiple log files
508/// for any given day (because of the rotation-on-size rule). This feature can
509/// be disabled dynamically later:
510/// @code
511/// observer->disableSizeRotation();
512/// return 0;
513/// }
514/// @endcode
515/// @}
516/** @} */
517/** @} */
518
519/** @addtogroup bal
520 * @{
521 */
522/** @addtogroup ball
523 * @{
524 */
525/** @addtogroup ball_fileobserver
526 * @{
527 */
528
529#include <balscm_version.h>
530
531#include <ball_cstdioobserver.h>
532#include <ball_fileobserver2.h>
533#include <ball_observer.h>
536#include <ball_severity.h>
537
538#ifndef BDE_OMIT_INTERNAL_DEPRECATED
540#endif // BDE_OMIT_INTERNAL_DEPRECATED
541
543
544#include <bsla_deprecated.h>
545
546#include <bslma_allocator.h>
548
550
551#include <bslmt_mutex.h>
552
553#include <bsls_keyword.h>
554#include <bsls_libraryfeatures.h>
555
556#include <bsl_memory.h>
557#include <bsl_string.h>
558
559#include <string> // 'std::string', 'std::pmr::string'
560
561
562namespace ball {
563
564class Context;
565class Record;
566
567 // ==================
568 // class FileObserver
569 // ==================
570
571/// This class implements the `Observer` protocol. The `publish` method of
572/// this class outputs the log records that it receives to `stdout` and
573/// optionally to a user-specified file. This class is thread-safe;
574/// different threads can operate on an object concurrently. This class is
575/// exception-neutral with no guarantee of rollback. In no event is memory
576/// leaked.
577///
578/// See @ref ball_fileobserver
579class FileObserver : public Observer {
580
581 // TYPES
582
583 /// `LogRecordFunctor` is an alias for the type of the functor used for
584 /// formatting log records to a stream.
586
588
589 // DATA
590 mutable
591 bslmt::Mutex d_mutex; // serialize operations
592
593 bool d_userFieldsLoggingFlag; // `true` if user-defined fields
594 // published (!DEPRECATED!)
595
596 Severity::Level d_stdoutThreshold; // minimum severity for records
597 // that'll be logged to `stdout`
598
599 bool d_stdoutUsesLongFormat; // `true` if records published to
600 // `stdout` in regular (long)
601 // format, otherwise short format
602 // is used
603
604 bsl::string d_stdoutLongFormat; // initially set to default long
605 // format for records printed to
606 // `stdout`; may be later
607 // updated by `setLogFormat`
608
609 bsl::string d_stdoutShortFormat; // default short format for
610 // records printed to `stdout`
611
612
613 CstdioObserver d_stdoutObserver; // forwards stdout operations to
614 // this observer
615
616 FileObserver2 d_fileObserver2; // forward file operations to
617 // this object
618
619 private:
620 // NOT IMPLEMENTED
622 FileObserver& operator=(const FileObserver&);
623
624 private:
625 // PRIVATE MANIPULATORS
626
627 /// Set the format specifications for log records written to the log file
628 /// `logFileFormat`. See {Log Record Formatting} for details on the syntax
629 /// of format specifications. Return zero if the format is valid and the
630 /// corresponding formatter has been set. Otherwise, if the format is
631 /// invalid, return a non-zero value and do not change the formatter.
632 int setFileLogFormatUnlocked(const char *logFileFormat);
633
634 /// Set the format specifications for log records written to `stdout` to
635 /// the `stdoutFormat`. If the default short output format is currently in
636 /// effect (for logging to `stdout`) this method has the effect of calling
637 /// `enableStdoutLoggingPrefix` (see that method and
638 /// `disableStdoutLoggingPrefix`) and setting the format corresponding to
639 /// enabled `stdout` logging prefix to `stdoutFormat`. See {Log Record
640 /// Formatting} for details on the syntax of format specifications. Return
641 /// zero if the format is valid and the corresponding formatter has been
642 /// set. Otherwise, if the format is invalid, return a non-zero value and
643 /// do not change the formatter.
644 int setStdoutLogFormatUnlocked(const char *stdoutFormat);
645
646 public:
647 // TYPES
648
649 /// `OnFileRotationCallback` is an alias for a user-supplied callback
650 /// function that is invoked after the file observer attempts to rotate
651 /// its log file. The callback takes two arguments: (1) an integer
652 /// status value where 0 indicates a new log file was successfully
653 /// created and a non-zero value indicates an error occurred during
654 /// rotation, and (2) a string that provides the name of the rotated log
655 /// file if the rotation was successful. E.g.:
656 /// @code
657 /// void onLogFileRotation(int rotationStatus,
658 /// const bsl::string& rotatedLogFileName);
659 /// @endcode
661
662 // TRAITS
664
665 // CREATORS
666
667 /// Create a file observer that publishes log records to `stdout` if
668 /// their severity is at least as severe as the optionally specified
669 /// `stdoutThreshold` level, and has file logging initially disabled.
670 /// If `stdoutThreshold` is not specified, log records are published to
671 /// `stdout` if their severity is at least as severe as
672 /// `Severity::e_WARN`. Optionally specify a `basicAllocator` used to
673 /// supply memory. If `basicAllocator` is 0, the currently installed default allocator is used.
674 ///
675 /// \note Note that `isPublishInLocalTimeEnabled`
676 /// returns `false` following construction indicating that the timestamp
677 /// attribute of published records will be written in UTC time (see
678 /// `enablePublishInLocalTime`). Also note that independent default
679 /// record formats are in effect for `stdout` and file logging (see
680 /// `setLogFormat`).
682 explicit FileObserver(bslma::Allocator *basicAllocator);
684 bslma::Allocator *basicAllocator = 0);
685
686 /// Create a file observer that publishes log records to `stdout` if
687 /// their severity is at least as severe as the specified
688 /// `stdoutThreshold` level, and has file logging initially disabled.
689 /// The timestamp attribute of published records is written in local
690 /// time if the specified `publishInLocalTime` flag is `true`, and in
691 /// UTC time otherwise. Optionally specify a `basicAllocator` used to
692 /// supply memory. If `basicAllocator` is 0, the currently installed default allocator is used.
693 ///
694 /// \note Note that following construction
695 /// independent default record formats are in effect for `stdout` and
696 /// file logging (see `setLogFormat`).
698 bool publishInLocalTime,
699 bslma::Allocator *basicAllocator = 0);
700
701 /// Close the log file of this file observer if file logging is enabled,
702 /// and destroy this file observer.
704
705 // MANIPULATORS
706
707 /// Disable file logging for this file observer. This method has no effect if file logging is not enabled.
708 ///
709 /// \note Note that records
710 /// subsequently received through the `publish` method of this file
711 /// observer may still be logged to `stdout` after calling this method.
712 void disableFileLogging();
713
714 /// Disable log file rotation based on a periodic time interval for this
715 /// file observer. This method has no effect if
716 /// rotation-on-time-interval is not enabled.
717 ///
718 /// @deprecated Use @ref disableTimeIntervalRotation instead.
720
721 /// Disable log file rotation based on a periodic time interval for this
722 /// file observer. This method has no effect if
723 /// rotation-on-time-interval is not enabled.
725
726 /// Disable log file rotation based on log file size for this file
727 /// observer. This method has no effect if rotation-on-size is not
728 /// enabled.
729 void disableSizeRotation();
730
731 /// Disable this file observer from using the long output format when
732 /// logging to `stdout`. Henceforth, this file observer will use the
733 /// default short output format ("\n%s %f:%l %c %m %u\n") when logging
734 /// to `stdout`. This method has no effect if the long output format for `stdout` logging is not enabled.
735 ///
736 /// \note Note that this method omits
737 /// the "%d %p:%t " prefix from the default long output format.
739
740 /// Disable the logging of user-defined fields by this file observer.
741 /// This method has no effect if logging of user-defined fields is not
742 /// enabled, or if a format string other than the default one is in
743 /// effect.
744 ///
745 /// @deprecated Use @ref setLogFormat instead.
746 BSLA_DEPRECATED_MESSAGE("Use `setFormat` and attributes")
748
749 /// Disable publishing of the timestamp attribute of records in local
750 /// time by this file observer; henceforth, timestamps will be in UTC
751 /// time. This method has no effect if publishing in local time is not enabled.
752 ///
753 /// \note Note that this method also affects log filenames (see {Log
754 /// Filename Patterns}).
756
757 /// Enable logging of all records published to this file observer to a
758 /// file whose name is derived from the specified `logFilenamePattern`.
759 /// Return 0 on success, a positive value if file logging is already
760 /// enabled (with no effect), and a negative value otherwise. The
761 /// basename of `logFilenamePattern` may contain `%`-escape sequences
762 /// that are interpreted as follows:
763 /// @code
764 /// %Y - current year (4 digits with leading zeros)
765 /// %M - current month (2 digits with leading zeros)
766 /// %D - current day (2 digits with leading zeros)
767 /// %h - current hour (2 digits with leading zeros)
768 /// %m - current minute (2 digits with leading zeros)
769 /// %s - current second (2 digits with leading zeros)
770 /// %T - current datetime, equivalent to "%Y%M%D_%h%m%s"
771 /// %p - process ID
772 /// @endcode
773 /// Each time a log file is opened by this file observer (upon a
774 /// successful call to this method and following each log file
775 /// rotation), the name of the new log file is derived from
776 /// `logFilenamePattern` by interpreting the above recognized `%`-escape
777 /// sequences. If `isPublishInLocalTimeEnabled` returns `true`, the
778 /// `%`-escape sequences related to time will be substituted with local
779 /// time values, and UTC time values otherwise. See {Log Filename
780 /// Patterns}.
781 int enableFileLogging(const char *logFilenamePattern);
782
783 /// Enable logging of all records published to this file observer to a
784 /// file whose name is derived from the specified `logFilenamePattern`
785 /// and append a timestamp to the log filename if the specified
786 /// `appendTimestampFlag` is `true`. Return 0 on success, a positive
787 /// value if file logging is already enabled (with no effect), and a
788 /// negative value otherwise. If the `appendTimestampFlag` is `true`
789 /// and `logFilenamePattern` does not contain any `%`-escape sequences,
790 /// this method behaves as if ".%T" is appended to `logFilenamePattern`.
791 ///
792 /// @deprecated Use @ref enableFileLogging(logFilenamePattern) instead
793 /// (use the ".%T" pattern to replicate `true == appendTimestampFlag`
794 /// behavior).
795 int enableFileLogging(const char *logFilenamePattern,
796 bool appendTimestampFlag);
797
798 /// Enable this file observer to use the long output format when logging
799 /// to `stdout`. Henceforth, this file observer will use the output
800 /// format for `stdout` logging that was set by the most recent call to
801 /// `setLogFormat`, or the default long output format
802 /// ("\n%d %p:%t %s %f:%l %c %m %u\n") if `setLogFormat` has not yet
803 /// been called. This method has no effect if the long output format
804 /// for `stdout` logging is already enabled.
806
807 /// Enable the logging of user-defined fields by this file observer.
808 /// This method has no effect if logging of user-defined fields is
809 /// already enabled, or if a format string other than the default one is
810 /// in effect.
811 ///
812 /// @deprecated Use @ref setLogFormat instead.
813 BSLA_DEPRECATED_MESSAGE("Use `setFormat` and attributes")
815
816 /// Enable publishing of the timestamp attribute of records in local
817 /// time by this file observer. This method has no effect if publishing in local time is already enabled.
818 ///
819 /// \note Note that this method also
820 /// affects log filenames (see {Log Filename Patterns}).
822
823 /// Process the specified log `record` having the specified publishing
824 /// `context` by writing `record` and `context` to the current log file
825 /// if file logging is enabled for this file observer, and to `stdout`
826 /// if the severity of `record` is at least as severe as the value
827 /// returned by `stdoutThreshold`.
828 ///
829 /// @deprecated Do not use.
830 void publish(const Record& record,
831 const Context& context) BSLS_KEYWORD_OVERRIDE;
832
833 /// Process the record referenced by the specified 'record' shared
834 /// pointer having the specified publishing 'context' by writing the
835 /// record and 'context' to the current log file if file logging is
836 /// enabled for this file observer, and to 'stdout' if the severity of
837 /// 'record' is at least as severe as the value returned by
838 /// 'stdoutThreshold'.
839 void publish(const bsl::shared_ptr<const Record>& record,
840 const Context& context)
842
843 /// Discard any shared references to `Record` objects that were supplied
844 /// to the `publish` method, and are held by this observer.
845 ///
846 /// \note Note that this operation should be called if resources underlying the
847 /// previously provided shared pointers must be released.
849
850 /// Forcefully perform a log file rotation by this file observer. Close
851 /// the current log file, rename the log file if necessary, and open a
852 /// new log file. This method has no effect if file logging is not
853 /// enabled. See {Rotated File Naming} for details on filenames of
854 /// rotated log files.
855 void forceRotation();
856
857 /// Set this file observer to perform a periodic log file rotation at
858 /// multiples of the specified `timeInterval`.
859 ///
860 /// \pre The behavior is undefined unless `0 < timeInterval.totalMilliseconds()`. This rule
861 /// replaces any rotation-on-time-interval rule currently in effect.
862 ///
863 /// @deprecated Use @ref rotateOnTimeInterval instead.
864 void rotateOnLifetime(const bdlt::DatetimeInterval& timeInterval);
865
866 /// Set this file observer to perform log file rotation when the size of
867 /// the file exceeds the specified `size` (in kilobytes). This rule
868 /// replaces any rotation-on-size rule currently in effect.
869 ///
870 /// \pre The behavior is undefined unless `size > 0`.
871 void rotateOnSize(int size);
872
873 /// Set this file observer to perform a periodic log file rotation at
874 /// multiples of the specified `interval`. Optionally specify a
875 /// `startTime` indicating the datetime to use as the starting point for
876 /// computing the periodic rotation schedule. If
877 /// `isPublishInLocalTimeEnabled` is `true`, the `startTime` is
878 /// interpreted as local time, and as a UTC time otherwise. If
879 /// `startTime` is not specified, the current time is used. This rule
880 /// replaces any rotation-on-time-interval rule currently in effect.
881 ///
882 /// \pre The behavior is undefined unless `0 < interval.totalMilliseconds()`.
883 ///
884 /// \note Note that `startTime` may be a fixed time in the past; e.g., a
885 /// reference time of `bdlt::Datetime(1, 1, 1)` and an interval of 24
886 /// hours would configure a periodic rotation at midnight each day.
887 void rotateOnTimeInterval(const bdlt::DatetimeInterval& interval);
888 void rotateOnTimeInterval(const bdlt::DatetimeInterval& interval,
889 const bdlt::Datetime& startTime);
890
891 /// Set the specified `onRotationCallback` to be invoked after each time
892 /// this file observer attempts to perform a log file rotation.
893 ///
894 /// \pre The behavior is undefined if the supplied function calls either
895 /// `setOnFileRotationCallback`, `forceRotation`, or `publish` on this
896 /// file observer (i.e., the supplied callback should *not* attempt to
897 /// write to the `ball` log).
899 const OnFileRotationCallback& onRotationCallback);
900
901 /// Set the minimum severity of records logged to `stdout` by this file observer to the specified `stdoutThreshold` level.
902 ///
903 /// \note Note that if the
904 /// value of `stdoutThreshold` is `Severity::e_OFF`, logging to `stdout`
905 /// is disabled.
907
908 /// Set the format specifications for log records written to the log
909 /// file and to `stdout` to the specified `logFileFormat` and
910 /// `stdoutFormat`, respectively. If the default short output format is
911 /// currently in effect for logging to `stdout`, this method has the
912 /// effect of calling `enableStdoutLoggingPrefix` (see that method and
913 /// `disableStdoutLoggingPrefix`) and setting the format corresponding to
914 /// enabled `stdout` logging prefix to `stdoutFormat`. See {Log Record
915 /// Formatting} for details on the syntax of format specifications. Return
916 /// zero if both formats are valid and have been set. Otherwise, if either
917 /// format is invalid, return a non-zero value. If one of the formats is
918 /// invalid, it will not be set, but the valid format will be set.
919 ///
920 /// \note Note that default formats are in effect following construction until a
921 /// format-setting method is called ("\n%d %p:%t %s %f:%l %c %m %u\n" for
922 /// both file and `stdout` logging). Also note that the default format
923 /// emits newline characters at the beginning and at the end of a log
924 /// record by default, so the user needs to add them explicitly to (text)
925 /// format strings to preserve that behavior.
926 ///
927 /// @deprecated Prefer `setFileLogFormat` and `setStdoutLogFormat`.
928 int setLogFormats(const char *logFileFormat, const char *stdoutFormat);
929 int setLogFormat( const char *logFileFormat, const char *stdoutFormat);
930
931 /// Set the format specifications for log records written to the log file
932 /// to `logFileFormat`. See {Log Record Formatting} for details on the
933 /// syntax of format specifications. Return zero if the format is valid
934 /// and the corresponding formatter has been set. Otherwise, if the format
935 /// is invalid, return a non-zero value and do not change the formatter.
936 ///
937 /// \note Note that default format is in effect following construction until a
938 /// format-setting method is called ("\n%d %p:%t %s %f:%l %c %m %u\n" for
939 /// both file and `stdout` logging).
940 int setFileLogFormat(const char *logFileFormat);
941
942 /// Set the format specifications for log records written to `stdout` to
943 /// `stdoutFormat`. If the default short output format is currently in
944 /// effect (for logging to `stdout`) this method has the effect of calling
945 /// `enableStdoutLoggingPrefix` (see that method and
946 /// `disableStdoutLoggingPrefix`) and setting the format corresponding to
947 /// enabled `stdout` logging prefix to `stdoutFormat`. See {Log Record
948 /// Formatting} for details on the syntax of format specifications. Return
949 /// zero if the format is valid and the corresponding formatter has been
950 /// set. Otherwise, if the format is invalid, return a non-zero value and do not change the formatter.
951 ///
952 /// \note Note that default format is in effect
953 /// following construction until a format-setting method is called
954 /// ("\n%d %p:%t %s %f:%l %c %m %u\n" for both file and `stdout` logging).
955 int setStdoutLogFormat(const char *stdoutFormat);
956
957 /// Suppress generating a unique log file name upon rotation if the
958 /// specified `suppress` is `true`, and generate a unique filename
959 /// otherwise. See {Rotated File Naming} for details.
960 void suppressUniqueFileNameOnRotation(bool suppress);
961
962 // ACCESSORS
963
964 /// Return the memory allocator used by this object.
965 bslma::Allocator *allocator() const;
966
967 /// Load the format specification for log records written by this file
968 /// observer to the log file into the specified `*logFileFormat` address
969 /// and the format specification for log records written to `stdout`
970 /// into the specified `*stdoutFormat` address. See {Log Record
971 /// Formatting} for details on the syntax of format specifications.
972 void getLogFormat(const char **logFileFormat,
973 const char **stdoutFormat) const;
974
975 /// Return the format specification for log records written to the log
976 /// file by this file observer. See {Log Record Formatting} for details
977 /// on the syntax of format specifications.
978 const bsl::string& getFileLogFormat() const;
979
980 /// Return the format specification for log records written to `stdout`
981 /// by this file observer. See {Log Record Formatting} for details on
982 /// the syntax of format specifications.
983 const bsl::string& getStdoutLogFormat() const;
984
985 /// Return `true` if file logging is enabled for this file observer, and
986 /// `false` otherwise. Load the optionally specified `result` with the
987 /// name of the current log file if file logging is enabled, and leave `result` unmodified otherwise.
988 ///
989 /// \note Note that records received through
990 /// the `publish` method of this file observer may still be logged to
991 /// `stdout` when this method returns `false`.
992 bool isFileLoggingEnabled() const;
993 bool isFileLoggingEnabled(bsl::string *result) const;
994 bool isFileLoggingEnabled(std::string *result) const;
995
996#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
997 /// Return `true` if file logging is enabled for this file observer, and
998 /// `false` otherwise. Load the specified `result` with the name of the
999 /// current log file if file logging is enabled, and leave `result` unmodified otherwise.
1000 ///
1001 /// \note Note that records received through the
1002 /// `publish` method of this file observer may still be logged to
1003 /// `stdout` when this method returns `false`.
1004 bool isFileLoggingEnabled(std::pmr::string *result) const;
1005#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1006
1007 /// Return `true` if this file observer uses the long output format when
1008 /// writing to `stdout`, and `false` otherwise (in which case the
1009 /// default short output format is used). See
1010 /// `enableStdoutLoggingPrefix` and `disableStdoutLoggingPrefix`.
1012
1013 /// Return `true` if the logging of user-defined fields is enabled for
1014 /// this file observer, and `false` otherwise.
1015 ///
1016 /// @deprecated Do not use.
1017 BSLA_DEPRECATED_MESSAGE("Use `setFormat` and attributes")
1019
1020 /// Return `true` if this file observer writes the timestamp attribute
1021 /// of records by default in local time, and `false` otherwise (in which case timestamps are written in UTC time by default).
1022 ///
1023 /// \note Note that the
1024 /// value returned by this method also affects log filenames (see {Log
1025 /// Filename Patterns}).
1027
1028 /// Return `true` if the log filename uniqueness check on rotation is
1029 /// suppressed, and false otherwise.
1031
1032 /// Return the difference between the local time and UTC time in effect when this file observer was constructed.
1033 ///
1034 /// \note Note that this value
1035 /// remains unchanged during the lifetime of this object and therefore
1036 /// may become incorrect when the difference between the local time and
1037 /// UTC time changes (e.g., when transitioning into or out of daylight
1038 /// savings time).
1039 ///
1040 /// @deprecated Use @ref bdlt::LocalTimeOffset instead.
1041 bdlt::DatetimeInterval localTimeOffset() const;
1042
1043 /// Return the lifetime of the log file that will trigger a file
1044 /// rotation by this file observer if rotation-on-lifetime is in effect,
1045 /// and a 0 time interval otherwise.
1046 bdlt::DatetimeInterval rotationLifetime() const;
1047
1048 /// Return the size (in kilobytes) of the log file that will trigger a
1049 /// file rotation by this file observer if rotation-on-size is in
1050 /// effect, and 0 otherwise.
1051 int rotationSize() const;
1052
1053 /// Return the minimum severity of records that will be logged to `stdout` by this file observer.
1054 ///
1055 /// \note Note that records with a threshold
1056 /// less severe than `stdoutThreshold()` may still be output to the log
1057 /// file if file logging is enabled.
1059};
1060
1061// ============================================================================
1062// INLINE DEFINITIONS
1063// ============================================================================
1064
1065 // ------------------
1066 // class FileObserver
1067 // ------------------
1068
1069// MANIPULATORS
1070inline
1071int FileObserver::setLogFormat(const char *logFileFormat,
1072 const char *stdoutFormat)
1073{
1074 return setLogFormats(logFileFormat, stdoutFormat);
1075}
1076
1077inline
1079{
1080 d_fileObserver2.disableFileLogging();
1081}
1082
1083inline
1088
1089inline
1091{
1092 d_fileObserver2.disableSizeRotation();
1093}
1094
1095inline
1100
1101inline
1102int FileObserver::enableFileLogging(const char *logFilenamePattern)
1103{
1104 return d_fileObserver2.enableFileLogging(logFilenamePattern);
1105}
1106
1107inline
1108int FileObserver::enableFileLogging(const char *logFilenamePattern,
1109 bool appendTimestampFlag)
1110{
1111 return d_fileObserver2.enableFileLogging(logFilenamePattern,
1112 appendTimestampFlag);
1113}
1114
1115inline
1117{
1118 d_fileObserver2.forceRotation();
1119}
1120
1121inline
1122void FileObserver::publish(const Record& record, const Context& context)
1123{
1125 publish(ptr, context);
1126}
1127
1128inline
1132
1133inline
1135{
1136 d_fileObserver2.rotateOnTimeInterval(timeInterval);
1137}
1138
1139inline
1141{
1142 d_fileObserver2.rotateOnSize(size);
1143}
1144
1145inline
1147{
1148 d_fileObserver2.rotateOnTimeInterval(interval);
1149}
1150
1151inline
1153 const bdlt::DatetimeInterval& interval,
1154 const bdlt::Datetime& startTime)
1155{
1156 d_fileObserver2.rotateOnTimeInterval(interval, startTime);
1157}
1158
1159inline
1161 const OnFileRotationCallback& onRotationCallback)
1162{
1163 d_fileObserver2.setOnFileRotationCallback(onRotationCallback);
1164}
1165
1166inline
1168{
1169 d_fileObserver2.suppressUniqueFileNameOnRotation(suppress);
1170}
1171
1172// ACCESSORS
1173inline
1175{
1176 return d_fileObserver2.isFileLoggingEnabled();
1177}
1178
1179inline
1181{
1182 return d_fileObserver2.isFileLoggingEnabled(result);
1183}
1184
1185inline
1186bool FileObserver::isFileLoggingEnabled(std::string *result) const
1187{
1188 return d_fileObserver2.isFileLoggingEnabled(result);
1189}
1190
1191#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1192inline
1193bool FileObserver::isFileLoggingEnabled(std::pmr::string *result) const
1194{
1195 return d_fileObserver2.isFileLoggingEnabled(result);
1196}
1197#endif //BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1198
1199inline
1201{
1202 return d_fileObserver2.isSuppressUniqueFileNameOnRotation();
1203}
1204
1205inline
1207{
1208 return d_fileObserver2.localTimeOffset();
1209}
1210
1211inline
1213{
1214 return d_fileObserver2.rotationLifetime();
1215}
1216
1217inline
1219{
1220 return d_fileObserver2.rotationSize();
1221}
1222
1223} // close package namespace
1224
1225
1226#endif
1227
1228// ----------------------------------------------------------------------------
1229// Copyright 2015 Bloomberg Finance L.P.
1230//
1231// Licensed under the Apache License, Version 2.0 (the "License");
1232// you may not use this file except in compliance with the License.
1233// You may obtain a copy of the License at
1234//
1235// http://www.apache.org/licenses/LICENSE-2.0
1236//
1237// Unless required by applicable law or agreed to in writing, software
1238// distributed under the License is distributed on an "AS IS" BASIS,
1239// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1240// See the License for the specific language governing permissions and
1241// limitations under the License.
1242// ----------------------------- END-OF-FILE ----------------------------------
1243
1244/** @} */
1245/** @} */
1246/** @} */
Definition ball_context.h:297
Definition ball_cstdioobserver.h:267
Definition ball_fileobserver2.h:478
void rotateOnSize(int size)
void rotateOnTimeInterval(const bdlt::DatetimeInterval &interval)
bool isSuppressUniqueFileNameOnRotation() const
bdlt::DatetimeInterval rotationLifetime() const
bdlt::DatetimeInterval localTimeOffset() const
bool isFileLoggingEnabled() const
int rotationSize() const
void disableTimeIntervalRotation()
void setOnFileRotationCallback(const OnFileRotationCallback &onRotationCallback)
int enableFileLogging(const char *logFilenamePattern)
void suppressUniqueFileNameOnRotation(bool suppress)
Definition ball_fileobserver.h:579
FileObserver(Severity::Level stdoutThreshold, bool publishInLocalTime, bslma::Allocator *basicAllocator=0)
int enableFileLogging(const char *logFilenamePattern)
Definition ball_fileobserver.h:1102
bslma::Allocator * allocator() const
Return the memory allocator used by this object.
void getLogFormat(const char **logFileFormat, const char **stdoutFormat) const
bool isSuppressUniqueFileNameOnRotation() const
Definition ball_fileobserver.h:1200
void rotateOnLifetime(const bdlt::DatetimeInterval &timeInterval)
Definition ball_fileobserver.h:1134
void releaseRecords() BSLS_KEYWORD_OVERRIDE
Definition ball_fileobserver.h:1129
bdlt::DatetimeInterval rotationLifetime() const
Definition ball_fileobserver.h:1212
bool isFileLoggingEnabled() const
Definition ball_fileobserver.h:1174
void disablePublishInLocalTime()
bool isStdoutLoggingPrefixEnabled() const
void disableSizeRotation()
Definition ball_fileobserver.h:1090
void enablePublishInLocalTime()
void disableLifetimeRotation()
Definition ball_fileobserver.h:1084
void disableStdoutLoggingPrefix()
void rotateOnSize(int size)
Definition ball_fileobserver.h:1140
bool isUserFieldsLoggingEnabled() const
BSLMF_NESTED_TRAIT_DECLARATION(FileObserver, bslma::UsesBslmaAllocator)
void setStdoutThreshold(Severity::Level stdoutThreshold)
void setOnFileRotationCallback(const OnFileRotationCallback &onRotationCallback)
Definition ball_fileobserver.h:1160
bdlt::DatetimeInterval localTimeOffset() const
Definition ball_fileobserver.h:1206
bool isPublishInLocalTimeEnabled() const
void rotateOnTimeInterval(const bdlt::DatetimeInterval &interval)
Definition ball_fileobserver.h:1146
int setLogFormat(const char *logFileFormat, const char *stdoutFormat)
Definition ball_fileobserver.h:1071
void disableTimeIntervalRotation()
Definition ball_fileobserver.h:1096
int setStdoutLogFormat(const char *stdoutFormat)
FileObserver2::OnFileRotationCallback OnFileRotationCallback
Definition ball_fileobserver.h:660
int setFileLogFormat(const char *logFileFormat)
void disableUserFieldsLogging()
void suppressUniqueFileNameOnRotation(bool suppress)
Definition ball_fileobserver.h:1167
void forceRotation()
Definition ball_fileobserver.h:1116
FileObserver(Severity::Level stdoutThreshold, bslma::Allocator *basicAllocator=0)
int setLogFormats(const char *logFileFormat, const char *stdoutFormat)
const bsl::string & getStdoutLogFormat() const
void disableFileLogging()
Definition ball_fileobserver.h:1078
void enableStdoutLoggingPrefix()
int rotationSize() const
Definition ball_fileobserver.h:1218
void enableUserFieldsLogging()
const bsl::string & getFileLogFormat() const
FileObserver(bslma::Allocator *basicAllocator)
Severity::Level stdoutThreshold() const
~FileObserver() BSLS_KEYWORD_OVERRIDE
void publish(const Record &record, const Context &context) BSLS_KEYWORD_OVERRIDE
Definition ball_fileobserver.h:1122
Definition ball_observer.h:235
Definition ball_record.h:176
Definition bdlt_datetimeinterval.h:201
Definition bdlt_datetime.h:330
Definition bslstl_string.h:1252
Forward declaration.
Definition bslstl_function.h:946
Definition bslstl_sharedptr.h:1838
Definition bslma_allocator.h:545
Definition bslmt_mutex.h:317
#define BSLA_DEPRECATED_MESSAGE(message)
Definition bsla_deprecated.h:310
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:695
Definition ball_administration.h:214
Definition bbldc_basicisma30360.h:112
Definition bdlat_valuetypefunctions.h:939
Definition baljsn_encoder_testtypes.h:76
Definition bdldfp_decimal.h:5549
Enum
Timezone setting for timestamps in log record formatters.
Definition ball_recordformattertimezone.h:114
Definition ball_severity.h:169
Level
Definition ball_severity.h:172
Definition bslma_usesbslmaallocator.h:344
Definition bslstl_sharedptr.h:4289