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

Observer that publishes log records to a user&hyphen;specified file&period;

== Synopsis

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

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

== Description

This class implements the `Observer` protocol&period; The `publish` method of this class outputs the log records that it receives 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;

== 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/FileObserver2/LogRecordFunctor.adoc[`LogRecordFunctor`] 
| `LogRecordFunctor` is an alias for the type of the functor used for formatting log records to a stream&period;
| xref:BloombergLP/ball/FileObserver2/OnFileRotationCallback.adoc[`OnFileRotationCallback`] 
| Callback invoked after each attempt to rotate the log file&period;
| xref:BloombergLP/ball/FileObserver2/RecordFormatter.adoc[`RecordFormatter`] 
| `RecordFormatter` is an alias for the type of the functor used for formatting log records to a stream&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/ball/FileObserver2/2constructor.adoc[`FileObserver2`]         [.small]#[constructor]#
| Create a file observer with file logging initially disabled&period;
| xref:BloombergLP/ball/FileObserver2/2destructor.adoc[`&#126;FileObserver2`] [.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/FileObserver2/disableFileLogging.adoc[`disableFileLogging`] 
| Disable file logging for this file observer&period;
| xref:BloombergLP/ball/FileObserver2/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/FileObserver2/disablePublishInLocalTime.adoc[`disablePublishInLocalTime`] 
| Disable publishing of record timestamps in local time&period;
| xref:BloombergLP/ball/FileObserver2/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/FileObserver2/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/FileObserver2/enableFileLogging-0b.adoc[`enableFileLogging`] 
| `enableFileLogging` overloads
| xref:BloombergLP/ball/FileObserver2/enablePublishInLocalTime.adoc[`enablePublishInLocalTime`] 
| Enable publishing of record timestamps in local time&period;
| xref:BloombergLP/ball/FileObserver2/forceRotation.adoc[`forceRotation`] 
| Force an immediate log file rotation by this observer&period;
| xref:BloombergLP/ball/FileObserver2/getFormat.adoc[`getFormat`] 
| Return the format config of the last successful `setFormat` call&period;
| xref:BloombergLP/ball/FileObserver2/isFileLoggingEnabled-00.adoc[`isFileLoggingEnabled`] 
| `isFileLoggingEnabled` overloads
| xref:BloombergLP/ball/FileObserver2/isPublishInLocalTimeEnabled.adoc[`isPublishInLocalTimeEnabled`] 
| Return `true` if published timestamps are written in local time&period;
| xref:BloombergLP/ball/FileObserver2/isSuppressUniqueFileNameOnRotation.adoc[`isSuppressUniqueFileNameOnRotation`] 
| Return `true` if the log filename uniqueness check on rotation is suppressed, and false otherwise&period;
| xref:BloombergLP/ball/FileObserver2/localTimeOffset.adoc[`localTimeOffset`] 
| Return the local&hyphen;minus&hyphen;UTC offset captured at construction&period;
| xref:BloombergLP/ball/FileObserver2/publish-09.adoc[`publish`] 
| Publish the specified log `record` with the given `context`&period;
| xref:BloombergLP/ball/FileObserver2/releaseRecords.adoc[`releaseRecords`]  [.small]#[virtual]#
| Discard shared references to published `Record` objects held by this observer&period;
| xref:BloombergLP/ball/FileObserver2/rotateOnLifetime.adoc[`rotateOnLifetime`] 
| Configure periodic log file rotation at the specified `timeInterval`&period;
| xref:BloombergLP/ball/FileObserver2/rotateOnSize.adoc[`rotateOnSize`] 
| Rotate the log file when its size exceeds the specified `size`&period;
| xref:BloombergLP/ball/FileObserver2/rotateOnTimeInterval-0b.adoc[`rotateOnTimeInterval`] 
| `rotateOnTimeInterval` overloads
| xref:BloombergLP/ball/FileObserver2/rotationLifetime.adoc[`rotationLifetime`] 
| Return the log file lifetime that triggers rotation, or zero&period;
| xref:BloombergLP/ball/FileObserver2/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/FileObserver2/setFormat.adoc[`setFormat`] 
| Set the log&hyphen;file record format from the specified `format` string&period;
| xref:BloombergLP/ball/FileObserver2/setLogFileFunctor.adoc[`setLogFileFunctor`] 
| Set the formatting functor used when writing records to the log file&period;
| xref:BloombergLP/ball/FileObserver2/setOnFileRotationCallback.adoc[`setOnFileRotationCallback`] 
| Set the callback invoked after each log file rotation attempt&period;
| xref:BloombergLP/ball/FileObserver2/suppressUniqueFileNameOnRotation.adoc[`suppressUniqueFileNameOnRotation`] 
| Suppress or enable unique filenames when rotating the log file&period;
| xref:BloombergLP/ball/FileObserver2/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;FileObserver2, UsesBslmaAllocator&gt;`] 
| Declare that this type uses a `bslma` allocator&period;
|===



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