API
 
Loading...
Searching...
No Matches
MagAOX::logger::logFileRaw< verboseT > Class Template Reference

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

#include <logFileRaw.hpp>

Collaboration diagram for MagAOX::logger::logFileRaw< verboseT >:
Collaboration graph

Public Member Functions

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

Protected Member Functions

mx::error_t createFile (flatlogs::timespecX &ts)
 Create a new file.
 

Protected Attributes

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

Detailed Description

template<class verboseT = XWC_DEFAULT_VERBOSITY>
class MagAOX::logger::logFileRaw< verboseT >

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]/[name]_YYYYMMDDHHMMSSNNNNNNNNN.[ext] where fields in [] are configurable.

The timestamp in the file name is from the first entry of the file.

Definition at line 36 of file logFileRaw.hpp.

Constructor & Destructor Documentation

◆ logFileRaw()

template<class verboseT >
MagAOX::logger::logFileRaw< verboseT >::logFileRaw ( )

Default constructor.

Currently does nothing.

Definition at line 165 of file logFileRaw.hpp.

◆ ~logFileRaw()

template<class verboseT >
MagAOX::logger::logFileRaw< verboseT >::~logFileRaw ( )

Destructor.

Closes the file if open

Definition at line 170 of file logFileRaw.hpp.

Member Function Documentation

◆ close()

template<class verboseT >
mx::error_t MagAOX::logger::logFileRaw< verboseT >::close ( )

Close the file pointer.

Sets m_fout to nullptr after calling fclose regardless of error.

Returns
0 on success
-1 on error

Definition at line 316 of file logFileRaw.hpp.

Referenced by libXWCTest::loggerTest::logFileRawTest::TEST_CASE().

◆ createFile()

template<class verboseT >
mx::error_t MagAOX::logger::logFileRaw< verboseT >::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]/YYYY_MM_DD/[name]_YYYYMMDDHHMMSSNNNNNNNNN.[ext]

Returns
0 on success
-1 on error
Parameters
[in]tsA MagAOX timespec, used to set the timestamp

Definition at line 336 of file logFileRaw.hpp.

References MagAOX::file::fileTimeRelPath(), flatlogs::timespecX::time_ns, and flatlogs::timespecX::time_s.

◆ flush()

template<class verboseT >
mx::error_t MagAOX::logger::logFileRaw< verboseT >::flush ( )

Flush the stream.

Calls fflush. See issue #192

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

Definition at line 301 of file logFileRaw.hpp.

◆ logExt() [1/2]

template<class verboseT >
std::string MagAOX::logger::logFileRaw< verboseT >::logExt ( )

Get the log extension.

Returns
the current value of m_logExt.

Definition at line 245 of file logFileRaw.hpp.

◆ logExt() [2/2]

template<class verboseT >
mx::error_t MagAOX::logger::logFileRaw< verboseT >::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 226 of file logFileRaw.hpp.

Referenced by libXWCTest::loggerTest::logFileRawTest::TEST_CASE(), libXWCTest::loggerTest::logFileRawTest::TEST_CASE(), and libXWCTest::loggerTest::logFileRawTest::TEST_CASE().

◆ logName() [1/2]

template<class verboseT >
std::string MagAOX::logger::logFileRaw< verboseT >::logName ( )

Get the name.

Returns
the current value of _name.

Definition at line 220 of file logFileRaw.hpp.

◆ logName() [2/2]

template<class verboseT >
mx::error_t MagAOX::logger::logFileRaw< verboseT >::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 201 of file logFileRaw.hpp.

Referenced by libXWCTest::loggerTest::logFileRawTest::TEST_CASE(), libXWCTest::loggerTest::logFileRawTest::TEST_CASE(), and libXWCTest::loggerTest::logFileRawTest::TEST_CASE().

◆ logPath() [1/2]

template<class verboseT >
std::string MagAOX::logger::logFileRaw< verboseT >::logPath ( )

Get the path.

Returns
the current value of m_logPath.

Definition at line 195 of file logFileRaw.hpp.

◆ logPath() [2/2]

template<class verboseT >
mx::error_t MagAOX::logger::logFileRaw< verboseT >::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 176 of file logFileRaw.hpp.

Referenced by libXWCTest::loggerTest::logFileRawTest::TEST_CASE().

◆ maxLogSize() [1/2]

template<class verboseT >
size_t MagAOX::logger::logFileRaw< verboseT >::maxLogSize ( )

Get the maximum file size.

Returns
the current value of m_maxLogSize

Definition at line 270 of file logFileRaw.hpp.

◆ maxLogSize() [2/2]

template<class verboseT >
mx::error_t MagAOX::logger::logFileRaw< verboseT >::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 251 of file logFileRaw.hpp.

Referenced by libXWCTest::loggerTest::logFileRawTest::TEST_CASE(), and libXWCTest::loggerTest::logFileRawTest::TEST_CASE().

◆ writeLog()

template<class verboseT >
mx::error_t MagAOX::logger::logFileRaw< verboseT >::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 276 of file logFileRaw.hpp.

References flatlogs::logHeader::timespec(), and flatlogs::logHeader::totalSize().

Referenced by libXWCTest::loggerTest::logFileRawTest::TEST_CASE().

Member Data Documentation

◆ m_currFileSize

template<class verboseT = XWC_DEFAULT_VERBOSITY>
size_t MagAOX::logger::logFileRaw< verboseT >::m_currFileSize { 0 }
protected

The current file size.

Definition at line 56 of file logFileRaw.hpp.

◆ m_fout

template<class verboseT = XWC_DEFAULT_VERBOSITY>
FILE* MagAOX::logger::logFileRaw< verboseT >::m_fout { 0 }
protected

The file pointer.

Definition at line 54 of file logFileRaw.hpp.

◆ m_logExt

template<class verboseT = XWC_DEFAULT_VERBOSITY>
std::string MagAOX::logger::logFileRaw< verboseT >::m_logExt { MAGAOX_default_logExt }
protected

The extension for the log files.

Definition at line 45 of file logFileRaw.hpp.

◆ m_logName

template<class verboseT = XWC_DEFAULT_VERBOSITY>
std::string MagAOX::logger::logFileRaw< verboseT >::m_logName { "xlog" }
protected

The base name for the log files.

Definition at line 44 of file logFileRaw.hpp.

◆ m_logPath

template<class verboseT = XWC_DEFAULT_VERBOSITY>
std::string MagAOX::logger::logFileRaw< verboseT >::m_logPath { "." }
protected

The base path for the log files.

Definition at line 43 of file logFileRaw.hpp.

◆ m_maxLogSize

template<class verboseT = XWC_DEFAULT_VERBOSITY>
size_t MagAOX::logger::logFileRaw< verboseT >::m_maxLogSize { MAGAOX_default_max_logSize }
protected

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

Definition at line 47 of file logFileRaw.hpp.


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