xrpld
Loading...
Searching...
No Matches
xrpl::Logs::File Class Reference

Manages a system file containing logged output. More...

Collaboration diagram for xrpl::Logs::File:

Public Member Functions

 File ()
 Construct with no associated system file.
 ~File ()=default
 Destroy the object.
bool isOpen () const noexcept
 Determine if a system file is associated with the log.
bool open (boost::filesystem::path const &path)
 Associate a system file with the log.
bool closeAndReopen ()
 Close and re-open the system file associated with the log This assists in interoperating with external log management tools.
void close ()
 Close the system file if it is open.
void write (char const *text)
 write to the log file.
void writeln (char const *text)
 write to the log file and append an end of line marker.
void write (std::string const &str)
 Write to the log file using std::string.
void writeln (std::string const &str)

Private Attributes

std::unique_ptr< std::ofstreamstream_
boost::filesystem::path path_

Detailed Description

Manages a system file containing logged output.

The system file remains open during program execution. Interfaces are provided for interoperating with standard log management tools like logrotate(8): http://linuxcommand.org/man_pages/logrotate8.html

Note
None of the listed interfaces are thread-safe.

Definition at line 49 of file Log.h.

Constructor & Destructor Documentation

◆ File()

xrpl::Logs::File::File ( )

Construct with no associated system file.

A system file may be associated later with open.

See also
open

Definition at line 46 of file Log.cpp.

◆ ~File()

xrpl::Logs::File::~File ( )
default

Destroy the object.

If a system file is associated, it will be flushed and closed.

Member Function Documentation

◆ isOpen()

bool xrpl::Logs::File::isOpen ( ) const
nodiscardnoexcept

Determine if a system file is associated with the log.

Returns
true if a system file is associated and opened for writing.

Definition at line 51 of file Log.cpp.

◆ open()

bool xrpl::Logs::File::open ( boost::filesystem::path const & path)

Associate a system file with the log.

If the file does not exist an attempt is made to create it and open it for writing. If the file already exists an attempt is made to open it for appending. If a system file is already associated with the log, it is closed first.

Returns
true if the file was opened.

Definition at line 57 of file Log.cpp.

◆ closeAndReopen()

bool xrpl::Logs::File::closeAndReopen ( )

Close and re-open the system file associated with the log This assists in interoperating with external log management tools.

Returns
true if the file was opened.

Definition at line 80 of file Log.cpp.

◆ close()

void xrpl::Logs::File::close ( )

Close the system file if it is open.

Definition at line 88 of file Log.cpp.

◆ write() [1/2]

void xrpl::Logs::File::write ( char const * text)

write to the log file.

Does nothing if there is no associated system file.

Definition at line 94 of file Log.cpp.

◆ writeln() [1/2]

void xrpl::Logs::File::writeln ( char const * text)

write to the log file and append an end of line marker.

Does nothing if there is no associated system file.

Definition at line 101 of file Log.cpp.

◆ write() [2/2]

void xrpl::Logs::File::write ( std::string const & str)

Write to the log file using std::string.

Definition at line 107 of file Log.h.

◆ writeln() [2/2]

void xrpl::Logs::File::writeln ( std::string const & str)

Definition at line 113 of file Log.h.

Member Data Documentation

◆ stream_

std::unique_ptr<std::ofstream> xrpl::Logs::File::stream_
private

Definition at line 120 of file Log.h.

◆ path_

boost::filesystem::path xrpl::Logs::File::path_
private

Definition at line 121 of file Log.h.