winss
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
winss::LogTmpl< TMutex > Class Template Reference

The logger template. More...

#include <log.hpp>

Collaboration diagram for winss::LogTmpl< TMutex >:
Collaboration graph
[legend]

Public Member Functions

 LogTmpl (winss::NotOwningPtr< winss::LogStreamReader > reader, winss::NotOwningPtr< winss::LogStreamWriter > writer, const winss::LogSettings &settings)
 Log template constructor. More...
 
 LogTmpl (const LogTmpl &)=delete
 No copy. More...
 
 LogTmpl (LogTmpl &&)=delete
 No move. More...
 
int Start ()
 Starts the logging implementation. More...
 
LogTmploperator= (const LogTmpl &)=delete
 No copy. More...
 
LogTmploperator= (LogTmpl &&)=delete
 No move. More...
 

Static Public Attributes

static const int kMutexTaken = 100
 Log dir in use error. More...
 
static const int kFatalExitCode = 111
 Something went wrong. More...
 
static constexpr const char kCurrentLog [8] = "current"
 Log file. More...
 
static constexpr const char kArchivePrefix [2] = "@"
 File prefix. More...
 
static constexpr const char kMutexName [4] = "log"
 Mutex name. More...
 

Protected Member Functions

bool Rotate () const
 Rotates the current log file. More...
 
void CleanArchives () const
 Deletes old archive files. More...
 

Protected Attributes

winss::NotOwningPtr< winss::LogStreamReaderreader
 Log input. More...
 
winss::NotOwningPtr< winss::LogStreamWriterwriter
 Log output. More...
 
const winss::LogSettingssettings
 Logger settings. More...
 
fs::path current
 Current log file. More...
 
TMutex mutex
 Log dir global mutex. More...
 
std::regex pattern
 Log file pattern when rotating files. More...
 

Detailed Description

template<typename TMutex>
class winss::LogTmpl< TMutex >

The logger template.

Reads from STDIN and writes to a log file. It will occasionally rotate the log file when it gets too big.

Constructor & Destructor Documentation

template<typename TMutex >
winss::LogTmpl< TMutex >::LogTmpl ( winss::NotOwningPtr< winss::LogStreamReader reader,
winss::NotOwningPtr< winss::LogStreamWriter writer,
const winss::LogSettings settings 
)
inline

Log template constructor.

Parameters
readerThe log stream reader.
writerThe log stream writer.
settingsThe logger settings.

References winss::LogSettings::log_dir.

template<typename TMutex >
winss::LogTmpl< TMutex >::LogTmpl ( const LogTmpl< TMutex > &  )
delete

No copy.

template<typename TMutex >
winss::LogTmpl< TMutex >::LogTmpl ( LogTmpl< TMutex > &&  )
delete

No move.

Member Function Documentation

template<typename TMutex >
void winss::LogTmpl< TMutex >::CleanArchives ( ) const
inlineprotected

Deletes old archive files.

Search the directory given an archive pattern and delete the archives which exceed the total number of archives defined in the settings.

References winss::LogArchiveFile::file, FILESYSTEM, winss::LogSettings::log_dir, winss::LogSettings::number, and winss::LogArchiveFile::time.

template<typename TMutex >
LogTmpl& winss::LogTmpl< TMutex >::operator= ( const LogTmpl< TMutex > &  )
delete

No copy.

template<typename TMutex >
LogTmpl& winss::LogTmpl< TMutex >::operator= ( LogTmpl< TMutex > &&  )
delete

No move.

template<typename TMutex >
bool winss::LogTmpl< TMutex >::Rotate ( ) const
inlineprotected

Rotates the current log file.

Current file is closed and renamed then a new current file is opened.

Returns
True if the rotation succeeded and false otherwise.

References winss::LogStreamWriter::Close(), FILESYSTEM, winss::LogSettings::log_dir, and winss::LogStreamWriter::Open().

template<typename TMutex >
int winss::LogTmpl< TMutex >::Start ( )
inline

Starts the logging implementation.

Obtains a log on the log dir, starts reading from the reader and writing to the writer until EOF is reached. When a rotation occurs then clean archives will be invoked.

Returns
The return code.

References winss::LogStreamWriter::Close(), winss::Utils::ConvertToISOString(), winss::LogSettings::file_size, FILESYSTEM, winss::LogStreamReader::GetLine(), winss::LogStreamWriter::GetPos(), winss::LogStreamReader::IsEOF(), winss::LogSettings::log_dir, winss::LogStreamWriter::Open(), winss::LogSettings::timestamp, winss::LogStreamWriter::Write(), and winss::LogStreamWriter::WriteLine().

Member Data Documentation

template<typename TMutex >
fs::path winss::LogTmpl< TMutex >::current
protected

Current log file.

template<typename TMutex >
constexpr const char winss::LogTmpl< TMutex >::kArchivePrefix[2] = "@"
static

File prefix.

template<typename TMutex >
constexpr const char winss::LogTmpl< TMutex >::kCurrentLog[8] = "current"
static

Log file.

template<typename TMutex >
const int winss::LogTmpl< TMutex >::kFatalExitCode = 111
static

Something went wrong.

template<typename TMutex >
constexpr const char winss::LogTmpl< TMutex >::kMutexName[4] = "log"
static

Mutex name.

template<typename TMutex >
const int winss::LogTmpl< TMutex >::kMutexTaken = 100
static

Log dir in use error.

template<typename TMutex >
TMutex winss::LogTmpl< TMutex >::mutex
protected

Log dir global mutex.

template<typename TMutex >
std::regex winss::LogTmpl< TMutex >::pattern
protected

Log file pattern when rotating files.

template<typename TMutex >
winss::NotOwningPtr<winss::LogStreamReader> winss::LogTmpl< TMutex >::reader
protected

Log input.

template<typename TMutex >
const winss::LogSettings& winss::LogTmpl< TMutex >::settings
protected

Logger settings.

template<typename TMutex >
winss::NotOwningPtr<winss::LogStreamWriter> winss::LogTmpl< TMutex >::writer
protected

Log output.


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