API
MagAOX::logger::logFileRaw Class Reference

A class to manage raw binary log files. More...

#include <logFileRaw.hpp>

Inheritance diagram for MagAOX::logger::logFileRaw:
Inheritance graph
Collaboration diagram for MagAOX::logger::logFileRaw:
Collaboration graph

Public Member Functions

 logFileRaw ()
 Default constructor. More...
 
 ~logFileRaw ()
 Destructor. More...
 
int logPath (const std::string &newPath)
 Set the path. More...
 
std::string logPath ()
 Get the path. More...
 
int logName (const std::string &newName)
 Set the log name. More...
 
std::string logName ()
 Get the name. More...
 
int logExt (const std::string &newExt)
 Set the log extension. More...
 
std::string logExt ()
 Get the log extension. More...
 
int maxLogSize (size_t newMaxFileSize)
 Set the maximum file size. More...
 
size_t maxLogSize ()
 Get the maximum file size. More...
 
int writeLog (flatlogs::bufferPtrT &data)
 Write a log entry to the file. More...
 
int flush ()
 Flush the stream. More...
 
int close ()
 Close the file pointer. More...
 

Protected Member Functions

int createFile (flatlogs::timespecX &ts)
 Create a new file. More...
 

Protected Attributes

Configurable Parameters
std::string m_logPath {"."}
 The base path for the log files. More...
 
std::string m_logName {"xlog"}
 The base name for the log files. More...
 
std::string m_logExt {MAGAOX_default_logExt}
 The extension for the log files. More...
 
size_t m_maxLogSize {MAGAOX_default_max_logSize}
 The maximum file size in bytes. Default is 10 MB. More...
 
Internal State
FILE * m_fout {0}
 The file pointer. More...
 
size_t m_currFileSize {0}
 The current file size. More...
 

Detailed Description

A class to manage raw binary log files.

Manages a binary file containing MagAO-X logs.

The log entries are written as a binary stream of a configurable maximum size. If this size will be exceed by the next entry, then a new file is created.

Filenames have a standard form of: [path]/[name]_YYYYMMDDHHMMSSNNNNNNNNN.[ext] where fields in [] are configurable.

The timestamp is from the first entry of the file.

Definition at line 41 of file logFileRaw.hpp.

Constructor & Destructor Documentation

◆ logFileRaw()

MagAOX::logger::logFileRaw::logFileRaw ( )

Default constructor.

Currently does nothing.

Definition at line 17 of file logFileRaw.cpp.

◆ ~logFileRaw()

MagAOX::logger::logFileRaw::~logFileRaw ( )

Destructor.

Closes the file if open

Definition at line 21 of file logFileRaw.cpp.

Member Function Documentation

◆ close()

int MagAOX::logger::logFileRaw::close ( )

Close the file pointer.

Returns
0 on success
-1 on error

Definition at line 103 of file logFileRaw.cpp.

Referenced by ~logFileRaw().

◆ createFile()

int MagAOX::logger::logFileRaw::createFile ( flatlogs::timespecX ts)
protected

Create a new file.

Closes the current file if open. Then creates a new file with a name of the form [path]/[name]_YYYYMMDDHHMMSSNNNNNNNNN.[ext]

Returns
0 on success
-1 on error
Todo:
handle case where file exists (only if another instance tries at same ns – pathological)
Parameters
[in]tsA MagAOX timespec, used to set the timestamp

Definition at line 110 of file logFileRaw.cpp.

Referenced by writeLog().

◆ flush()

int MagAOX::logger::logFileRaw::flush ( )

Flush the stream.

Returns
0 on success
-1 on error
Todo:
this probably should be fsync, with appropriate error handling (see fsyncgate)

Definition at line 95 of file logFileRaw.cpp.

◆ logExt() [1/2]

std::string MagAOX::logger::logFileRaw::logExt ( )

Get the log extension.

Returns
the current value of m_logExt.

Definition at line 54 of file logFileRaw.cpp.

◆ logExt() [2/2]

int MagAOX::logger::logFileRaw::logExt ( const std::string &  newExt)

Set the log extension.

Returns
0 on success
-1 on error
Parameters
[in]newExtthe new value of m_logExt

Definition at line 48 of file logFileRaw.cpp.

◆ logName() [1/2]

std::string MagAOX::logger::logFileRaw::logName ( )

Get the name.

Returns
the current value of _name.

Definition at line 43 of file logFileRaw.cpp.

◆ logName() [2/2]

int MagAOX::logger::logFileRaw::logName ( const std::string &  newName)

Set the log name.

Returns
0 on success
-1 on error
Parameters
[in]newNamethe new value of m_logName

Definition at line 37 of file logFileRaw.cpp.

◆ logPath() [1/2]

std::string MagAOX::logger::logFileRaw::logPath ( )

Get the path.

Returns
the current value of m_logPath.

Definition at line 32 of file logFileRaw.cpp.

◆ logPath() [2/2]

int MagAOX::logger::logFileRaw::logPath ( const std::string &  newPath)

Set the path.

Returns
0 on success
-1 on error
Parameters
[in]newPaththe new value of _path

Definition at line 26 of file logFileRaw.cpp.

◆ maxLogSize() [1/2]

size_t MagAOX::logger::logFileRaw::maxLogSize ( )

Get the maximum file size.

Returns
the current value of m_maxLogSize

Definition at line 65 of file logFileRaw.cpp.

◆ maxLogSize() [2/2]

int MagAOX::logger::logFileRaw::maxLogSize ( size_t  newMaxFileSize)

Set the maximum file size.

Returns
0 on success
-1 on error
Parameters
[in]newMaxFileSizethe new value of _maxLogSize

Definition at line 59 of file logFileRaw.cpp.

◆ writeLog()

int MagAOX::logger::logFileRaw::writeLog ( flatlogs::bufferPtrT data)

Write a log entry to the file.

Checks if this write will exceed m_maxLogSize, and if so opens a new file. The new file will have the timestamp of this log entry.

Returns
0 on success
-1 on error
Parameters
[in]datathe log entry to write to disk

Definition at line 70 of file logFileRaw.cpp.

Member Data Documentation

◆ m_currFileSize

size_t MagAOX::logger::logFileRaw::m_currFileSize {0}
protected

The current file size.

Definition at line 62 of file logFileRaw.hpp.

Referenced by createFile(), and writeLog().

◆ m_fout

FILE* MagAOX::logger::logFileRaw::m_fout {0}
protected

The file pointer.

Definition at line 60 of file logFileRaw.hpp.

Referenced by close(), createFile(), flush(), and writeLog().

◆ m_logExt

std::string MagAOX::logger::logFileRaw::m_logExt {MAGAOX_default_logExt}
protected

The extension for the log files.

Definition at line 51 of file logFileRaw.hpp.

Referenced by createFile(), and logExt().

◆ m_logName

std::string MagAOX::logger::logFileRaw::m_logName {"xlog"}
protected

The base name for the log files.

Definition at line 50 of file logFileRaw.hpp.

Referenced by createFile(), and logName().

◆ m_logPath

std::string MagAOX::logger::logFileRaw::m_logPath {"."}
protected

The base path for the log files.

Definition at line 49 of file logFileRaw.hpp.

Referenced by createFile(), and logPath().

◆ m_maxLogSize

size_t MagAOX::logger::logFileRaw::m_maxLogSize {MAGAOX_default_max_logSize}
protected

The maximum file size in bytes. Default is 10 MB.

Definition at line 53 of file logFileRaw.hpp.

Referenced by maxLogSize(), and writeLog().


The documentation for this class was generated from the following files: