[#BloombergLP-ball-FileObserver]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/ball.adoc[ball]::FileObserver
:relfileprefix: ../../
:mrdocs:

This class implements the `Observer` protocol&period; The `publish` method of this class outputs the log records that it receives to `stdout` and optionally to a user&hyphen;specified file&period; This class is thread&hyphen;safe&semi; different threads can operate on an object concurrently&period; This class is exception&hyphen;neutral with no guarantee of rollback&period; In no event is memory leaked&period;

== Synopsis

Declared in `&lt;ball&lowbar;fileobserver&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class FileObserver
    : public xref:BloombergLP/ball/Observer.adoc[Observer]
----

== Base Classes

[cols="1,4"]
|===
| Name| Description
| `xref:BloombergLP/ball/Observer.adoc[Observer]`
| This class provides a protocol for receiving and processing log record output&period;
|===

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/ball/FileObserver/OnFileRotationCallback.adoc[`OnFileRotationCallback`] 
| `OnFileRotationCallback` is an alias for a user&hyphen;supplied callback function that is invoked after the file observer attempts to rotate its log file&period; The callback takes two arguments&colon; (1) an integer status value where 0 indicates a new log file was successfully created and a non&hyphen;zero value indicates an error occurred during rotation, and (2) a string that provides the name of the rotated log file if the rotation was successful&period; E&period;g&period;&colon; &grave; void onLogFileRotation(int rotationStatus, const bsl&colon;&colon;string&amp; rotatedLogFileName)&semi; &grave;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/ball/FileObserver/2constructor-0f.adoc[`FileObserver`]         [.small]#[constructor]#
| Constructors
| xref:BloombergLP/ball/FileObserver/2destructor.adoc[`&#126;FileObserver`] [.small]#[destructor]# [.small]#[virtual]#
| Close the log file of this file observer if file logging is enabled, and destroy this file observer&period;
| xref:BloombergLP/ball/FileObserver/allocator.adoc[`allocator`] 
| Return the memory allocator used by this object&period;
| xref:BloombergLP/ball/FileObserver/disableFileLogging.adoc[`disableFileLogging`] 
| Disable file logging for this file observer&period; This method has no effect if file logging is not enabled&period; Note that records subsequently received through the `publish` method of this file observer may still be logged to `stdout` after calling this method&period;
| xref:BloombergLP/ball/FileObserver/disableLifetimeRotation.adoc[`disableLifetimeRotation`] 
| Disable log file rotation based on a periodic time interval for this file observer&period; This method has no effect if rotation&hyphen;on&hyphen;time&hyphen;interval is not enabled&period;
| xref:BloombergLP/ball/FileObserver/disablePublishInLocalTime.adoc[`disablePublishInLocalTime`] 
| Disable publishing of the timestamp attribute of records in local time by this file observer&semi; henceforth, timestamps will be in UTC time&period; This method has no effect if publishing in local time is not enabled&period; Note that this method also affects log filenames (see &lcub;Log Filename Patterns&rcub;)&period;
| xref:BloombergLP/ball/FileObserver/disableSizeRotation.adoc[`disableSizeRotation`] 
| Disable log file rotation based on log file size for this file observer&period; This method has no effect if rotation&hyphen;on&hyphen;size is not enabled&period;
| xref:BloombergLP/ball/FileObserver/disableStdoutLoggingPrefix.adoc[`disableStdoutLoggingPrefix`] 
| Disable this file observer from using the long output format when logging to `stdout`&period; Henceforth, this file observer will use the default short output format (&quot;n%s %f&colon;%l %c %m %un&quot;) when logging to `stdout`&period; This method has no effect if the long output format for `stdout` logging is not enabled&period; Note that this method omits the &quot;%d %p&colon;%t &quot; prefix from the default long output format&period;
| xref:BloombergLP/ball/FileObserver/disableTimeIntervalRotation.adoc[`disableTimeIntervalRotation`] 
| Disable log file rotation based on a periodic time interval for this file observer&period; This method has no effect if rotation&hyphen;on&hyphen;time&hyphen;interval is not enabled&period;
| xref:BloombergLP/ball/FileObserver/disableUserFieldsLogging.adoc[`disableUserFieldsLogging`]  [.small]#[deprecated]#
| Disable the logging of user&hyphen;defined fields by this file observer&period; This method has no effect if logging of user&hyphen;defined fields is not enabled, or if a format string other than the default one is in effect&period;
| xref:BloombergLP/ball/FileObserver/enableFileLogging-06.adoc[`enableFileLogging`] 
| `enableFileLogging` overloads
| xref:BloombergLP/ball/FileObserver/enablePublishInLocalTime.adoc[`enablePublishInLocalTime`] 
| Enable publishing of the timestamp attribute of records in local time by this file observer&period; This method has no effect if publishing in local time is already enabled&period; Note that this method also affects log filenames (see &lcub;Log Filename Patterns&rcub;)&period;
| xref:BloombergLP/ball/FileObserver/enableStdoutLoggingPrefix.adoc[`enableStdoutLoggingPrefix`] 
| Enable this file observer to use the long output format when logging to `stdout`&period; Henceforth, this file observer will use the output format for `stdout` logging that was set by the most recent call to `setLogFormat`, or the default long output format (&quot;n%d %p&colon;%t %s %f&colon;%l %c %m %un&quot;) if `setLogFormat` has not yet been called&period; This method has no effect if the long output format for `stdout` logging is already enabled&period;
| xref:BloombergLP/ball/FileObserver/enableUserFieldsLogging.adoc[`enableUserFieldsLogging`]  [.small]#[deprecated]#
| Enable the logging of user&hyphen;defined fields by this file observer&period; This method has no effect if logging of user&hyphen;defined fields is already enabled, or if a format string other than the default one is in effect&period;
| xref:BloombergLP/ball/FileObserver/forceRotation.adoc[`forceRotation`] 
| Forcefully perform a log file rotation by this file observer&period; Close the current log file, rename the log file if necessary, and open a new log file&period; This method has no effect if file logging is not enabled&period; See &lcub;Rotated File Naming&rcub; for details on filenames of rotated log files&period;
| xref:BloombergLP/ball/FileObserver/getFileLogFormat.adoc[`getFileLogFormat`] 
| Return the format specification for log records written to the log file by this file observer&period; See &lcub;Log Record Formatting&rcub; for details on the syntax of format specifications&period;
| xref:BloombergLP/ball/FileObserver/getLogFormat.adoc[`getLogFormat`] 
| Load the format specification for log records written by this file observer to the log file into the specified `&ast;logFileFormat` address and the format specification for log records written to `stdout` into the specified `&ast;stdoutFormat` address&period; See &lcub;Log Record Formatting&rcub; for details on the syntax of format specifications&period;
| xref:BloombergLP/ball/FileObserver/getStdoutLogFormat.adoc[`getStdoutLogFormat`] 
| Return the format specification for log records written to `stdout` by this file observer&period; See &lcub;Log Record Formatting&rcub; for details on the syntax of format specifications&period;
| xref:BloombergLP/ball/FileObserver/isFileLoggingEnabled-0657.adoc[`isFileLoggingEnabled`] 
| `isFileLoggingEnabled` overloads
| xref:BloombergLP/ball/FileObserver/isPublishInLocalTimeEnabled.adoc[`isPublishInLocalTimeEnabled`] 
| Return `true` if this file observer writes the timestamp attribute of records by default in local time, and `false` otherwise (in which case timestamps are written in UTC time by default)&period; Note that the value returned by this method also affects log filenames (see &lcub;Log Filename Patterns&rcub;)&period;
| xref:BloombergLP/ball/FileObserver/isStdoutLoggingPrefixEnabled.adoc[`isStdoutLoggingPrefixEnabled`] 
| Return `true` if this file observer uses the long output format when writing to `stdout`, and `false` otherwise (in which case the default short output format is used)&period; See `enableStdoutLoggingPrefix` and `disableStdoutLoggingPrefix`&period;
| xref:BloombergLP/ball/FileObserver/isSuppressUniqueFileNameOnRotation.adoc[`isSuppressUniqueFileNameOnRotation`] 
| Return `true` if the log filename uniqueness check on rotation is suppressed, and false otherwise&period;
| xref:BloombergLP/ball/FileObserver/isUserFieldsLoggingEnabled.adoc[`isUserFieldsLoggingEnabled`]  [.small]#[deprecated]#
| Return `true` if the logging of user&hyphen;defined fields is enabled for this file observer, and `false` otherwise&period;
| xref:BloombergLP/ball/FileObserver/localTimeOffset.adoc[`localTimeOffset`] 
| Return the difference between the local time and UTC time in effect when this file observer was constructed&period; Note that this value remains unchanged during the lifetime of this object and therefore may become incorrect when the difference between the local time and UTC time changes (e&period;g&period;, when transitioning into or out of daylight savings time)&period;
| xref:BloombergLP/ball/FileObserver/publish-0d.adoc[`publish`] 
| `publish` overloads
| xref:BloombergLP/ball/FileObserver/releaseRecords.adoc[`releaseRecords`]  [.small]#[virtual]#
| Discard any shared references to `Record` objects that were supplied to the `publish` method, and are held by this observer&period; Note that this operation should be called if resources underlying the previously provided shared pointers must be released&period;
| xref:BloombergLP/ball/FileObserver/rotateOnLifetime.adoc[`rotateOnLifetime`] 
| Set this file observer to perform a periodic log file rotation at multiples of the specified `timeInterval`&period; The behavior is undefined unless `0 &lt; timeInterval&period;totalMilliseconds()`&period; This rule replaces any rotation&hyphen;on&hyphen;time&hyphen;interval rule currently in effect&period;
| xref:BloombergLP/ball/FileObserver/rotateOnSize.adoc[`rotateOnSize`] 
| Set this file observer to perform log file rotation when the size of the file exceeds the specified `size` (in kilobytes)&period; This rule replaces any rotation&hyphen;on&hyphen;size rule currently in effect&period; The behavior is undefined unless `size &gt; 0`&period;
| xref:BloombergLP/ball/FileObserver/rotateOnTimeInterval-02.adoc[`rotateOnTimeInterval`] 
| `rotateOnTimeInterval` overloads
| xref:BloombergLP/ball/FileObserver/rotationLifetime.adoc[`rotationLifetime`] 
| Return the lifetime of the log file that will trigger a file rotation by this file observer if rotation&hyphen;on&hyphen;lifetime is in effect, and a 0 time interval otherwise&period;
| xref:BloombergLP/ball/FileObserver/rotationSize.adoc[`rotationSize`] 
| Return the size (in kilobytes) of the log file that will trigger a file rotation by this file observer if rotation&hyphen;on&hyphen;size is in effect, and 0 otherwise&period;
| xref:BloombergLP/ball/FileObserver/setFileLogFormat.adoc[`setFileLogFormat`] 
| Set the format specifications for log records written to the log file to `logFileFormat`&period; See &lcub;Log Record Formatting&rcub; for details on the syntax of format specifications&period; Return zero if the format is valid and the corresponding formatter has been set&period; Otherwise, if the format is invalid, return a non&hyphen;zero value and do not change the formatter&period; Note that default format is in effect following construction until a format&hyphen;setting method is called (&quot;n%d %p&colon;%t %s %f&colon;%l %c %m %un&quot; for both file and `stdout` logging)&period;
| xref:BloombergLP/ball/FileObserver/setLogFormat.adoc[`setLogFormat`] 
| Same as `setLogFormats`&period;
| xref:BloombergLP/ball/FileObserver/setLogFormats.adoc[`setLogFormats`] 
| Set the format specifications for log records written to the log file and to `stdout` to the specified `logFileFormat` and `stdoutFormat`, respectively&period; If the default short output format is currently in effect for logging to `stdout`, this method has the effect of calling `enableStdoutLoggingPrefix` (see that method and `disableStdoutLoggingPrefix`) and setting the format corresponding to enabled `stdout` logging prefix to `stdoutFormat`&period; See &lcub;Log Record Formatting&rcub; for details on the syntax of format specifications&period; Return zero if both formats are valid and have been set&period; Otherwise, if either format is invalid, return a non&hyphen;zero value&period; If one of the formats is invalid, it will not be set, but the valid format will be set&period; Note that default formats are in effect following construction until a format&hyphen;setting method is called (&quot;n%d %p&colon;%t %s %f&colon;%l %c %m %un&quot; for both file and `stdout` logging)&period; Also note that the default format emits newline characters at the beginning and at the end of a log record by default, so the user needs to add them explicitly to (text) format strings to preserve that behavior&period;
| xref:BloombergLP/ball/FileObserver/setOnFileRotationCallback.adoc[`setOnFileRotationCallback`] 
| Set the specified `onRotationCallback` to be invoked after each time this file observer attempts to perform a log file rotation&period; The behavior is undefined if the supplied function calls either `setOnFileRotationCallback`, `forceRotation`, or `publish` on this file observer (i&period;e&period;, the supplied callback should _not_ attempt to write to the `ball` log)&period;
| xref:BloombergLP/ball/FileObserver/setStdoutLogFormat.adoc[`setStdoutLogFormat`] 
| Set the format specifications for log records written to `stdout` to `stdoutFormat`&period; If the default short output format is currently in effect (for logging to `stdout`) this method has the effect of calling `enableStdoutLoggingPrefix` (see that method and `disableStdoutLoggingPrefix`) and setting the format corresponding to enabled `stdout` logging prefix to `stdoutFormat`&period; See &lcub;Log Record Formatting&rcub; for details on the syntax of format specifications&period; Return zero if the format is valid and the corresponding formatter has been set&period; Otherwise, if the format is invalid, return a non&hyphen;zero value and do not change the formatter&period; Note that default format is in effect following construction until a format&hyphen;setting method is called (&quot;n%d %p&colon;%t %s %f&colon;%l %c %m %un&quot; for both file and `stdout` logging)&period;
| xref:BloombergLP/ball/FileObserver/setStdoutThreshold.adoc[`setStdoutThreshold`] 
| Set the minimum severity of records logged to `stdout` by this file observer to the specified `stdoutThreshold` level&period; Note that if the value of `stdoutThreshold` is `Severity&colon;&colon;e&lowbar;OFF`, logging to `stdout` is disabled&period;
| xref:BloombergLP/ball/FileObserver/stdoutThreshold.adoc[`stdoutThreshold`] 
| Return the minimum severity of records that will be logged to `stdout` by this file observer&period; Note that records with a threshold less severe than `stdoutThreshold()` may still be output to the log file if file logging is enabled&period;
| xref:BloombergLP/ball/FileObserver/suppressUniqueFileNameOnRotation.adoc[`suppressUniqueFileNameOnRotation`] 
| Suppress generating a unique log file name upon rotation if the specified `suppress` is `true`, and generate a unique filename otherwise&period; See &lcub;Rotated File Naming&rcub; for details&period;
| xref:BloombergLP/ball/FileObserver/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;FileObserver, UsesBslmaAllocator&gt;`] 
| Declare that this type uses a `bslma` allocator&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
