rippled
Public Member Functions | Private Attributes | List of all members
ripple::Logs::File Class Reference

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

Collaboration diagram for ripple::Logs::File:
Collaboration graph
[legend]

Public Member Functions

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

Private Attributes

std::unique_ptr< std::ofstreamm_stream
 
boost::filesystem::path m_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 79 of file Log.h.

Constructor & Destructor Documentation

◆ File()

ripple::Logs::File::File ( )

Construct with no associated system file.

A system file may be associated later with open.

See also
open

Definition at line 52 of file Log.cpp.

◆ ~File()

ripple::Logs::File::~File ( )
default

Destroy the object.

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

Member Function Documentation

◆ isOpen()

bool ripple::Logs::File::isOpen ( ) const
noexcept

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 57 of file Log.cpp.

◆ open()

bool ripple::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 63 of file Log.cpp.

◆ closeAndReopen()

bool ripple::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 86 of file Log.cpp.

◆ close()

void ripple::Logs::File::close ( )

Close the system file if it is open.

Definition at line 94 of file Log.cpp.

◆ write() [1/2]

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

write to the log file.

Does nothing if there is no associated system file.

Definition at line 100 of file Log.cpp.

◆ writeln() [1/2]

void ripple::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 107 of file Log.cpp.

◆ write() [2/2]

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

Write to the log file using std::string.

Definition at line 137 of file Log.h.

◆ writeln() [2/2]

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

Definition at line 143 of file Log.h.

Member Data Documentation

◆ m_stream

std::unique_ptr<std::ofstream> ripple::Logs::File::m_stream
private

Definition at line 150 of file Log.h.

◆ m_path

boost::filesystem::path ripple::Logs::File::m_path
private

Definition at line 151 of file Log.h.