UTILLib 2.0
Common C++ library with utilities.
Loading...
Searching...
No Matches
util::log Namespace Reference

The log namespace is used for log related classes and functions. More...

Classes

class  IDirectory
 The class is simple wrapper around a directory/file tree structure. It is typically used in applications that needs to keep track of file changes in a root directory. More...
class  IFile
 Class that wraps a file object in a directory. More...
class  IListen
 An interface class that hides the actual implementation of the object. More...
class  IListenClient
 Class that define a TCP/IP client. More...
class  ILogger
 Interface against a generic logger. More...
class  ListenConfig
 Implement the shared memory list of listen server configurations. More...
struct  ListenPortConfig
 Defines a listen config item in the config memory. More...
class  ListenStream
 Support stream class when log messages to the listen functionality. More...
class  LogConfig
 Singleton class that is used for configure the default logger in an application. More...
struct  LogMessage
class  LogStream
 This class implements a stream interface around a log message. More...
class  TempDir
class  ThreadSafeQueue
 Implements a thread-safe queue. More...

Typedefs

using DirectoryList = std::map<std::string, std::unique_ptr<IDirectory>>
 Sorted list of directories.
using FileList = std::map<std::string, std::unique_ptr<IFile>>
 Sorted list of files in the directory.
using FilterList = std::vector<std::string>
 List of name filters.
using Loc = std::experimental::source_location

Enumerations

enum class  TypeOfListen { ListenProxyType = 0 , ListenServerType , ListenConsoleType }
 Defines the type of listen objects. More...
enum class  LogType {
  LogNothing = 0 , LogToConsole , LogToFile , LogToListen ,
  LogToSyslog
}
enum class  LogSeverity : uint8_t {
  kTrace = 0 , kDebug , kInfo , kNotice ,
  kWarning , kError , kCritical , kAlert ,
  kEmergency
}
 < Defines the log severity level More...

Functions

std::vector< ListenPortConfigGetListenConfigList ()
 Returns the list of available listen servers.
void AddListenConfig (const ListenPortConfig &port_config)
 Register a new listen server.
void DeleteListenConfig (uint16_t port)
 Removes a listen server from the list.
std::string ProgramDataPath ()
void LogDebug (const Loc &loc, const char *fmt,...)
 Creates a debug message message.
void LogInfo (const Loc &loc, const char *fmt,...)
 Creates an information message.
void LogError (const Loc &loc, const char *fmt,...)
 Creates an error message.
void LogString (const Loc &loc, LogSeverity severity, const std::string &message)
 Creates a generic message.
std::string FindNotepad ()
 Search and returns the path to the Notepad application.. Search primary for the Notepad++ application and second for the Notepad application.
bool BackupFiles (const std::string &filename, bool remove_file=true)
 Backup up a file with the 9 last changes.
std::string GetSeverityString (LogSeverity severity)
 Returns the log level as a string.

Detailed Description

The log namespace is used for all log related classes and functions.

Typedef Documentation

◆ DirectoryList

using util::log::DirectoryList = std::map<std::string, std::unique_ptr<IDirectory>>

A list of sub-directories of the IDirectory class. The key (first) is the name of the directory without path and the value (second) is a unique pointer to the directory object.

◆ FileList

using util::log::FileList = std::map<std::string, std::unique_ptr<IFile>>

Sorted list of files in the directory. Note that the key (first) is the filename without path.

◆ FilterList

using util::log::FilterList = std::vector<std::string>

List of name filters. Files are typical filtered by its extension for example '*.txt' while directories are filtered by its name for example 'obj'.

◆ Loc

using util::log::Loc = std::experimental::source_location

The Loc is a wrapper around the std::location library. This library is new in C++20.

Enumeration Type Documentation

◆ LogSeverity

enum class util::log::LogSeverity : uint8_t
strong
Enumerator
kTrace 

Trace or listen message.

kDebug 

Debug message.

kInfo 

Informational message.

kNotice 

Notice message. Notify the user.

kWarning 

Warning message.

kError 

Error message.

kCritical 

Critical message (device error)

kAlert 

Alert or alarm message.

kEmergency 

Fatal error message.

◆ LogType

enum class util::log::LogType
strong

\ brief Defines type of pre-defined loggers in the system

Enumerator
LogNothing 

No logger.

LogToConsole 

Log to the cout stream.

LogToFile 

Log to file.

LogToListen 

Log to listen window (system messages).

LogToSyslog 

Logs to a syslog server.

◆ TypeOfListen

enum class util::log::TypeOfListen
strong

Define type of listen (server) objects

Enumerator
ListenProxyType 

Forward the listen messages in shared memory.

ListenServerType 

TCP/IP server that forwards the listen messages.

ListenConsoleType 

Forward the listen messages to a console window.

Function Documentation

◆ AddListenConfig()

void util::log::AddListenConfig ( const ListenPortConfig & port_config)

Add a new listen server onto the shared memory list of servers. Note that the port should be unique.

Parameters
port_configServer configuration.

◆ BackupFiles()

bool util::log::BackupFiles ( const std::string & filename,
bool remove_file = true )

Backup a file by adding a sequence number 0..9 to the file (file_N.ext).

Parameters
filenameFull path to the file.
remove_fileIf set to true the file will be renamed to file_0. If set to false the file will copy its content to file_0. The latter is slower but safer.
Returns
True if successful

◆ DeleteListenConfig()

void util::log::DeleteListenConfig ( uint16_t port)

Removes a listen server from the shared memory list.

Parameters
portTCP/IP port of the server.

◆ FindNotepad()

std::string util::log::FindNotepad ( )
Returns
The path to the Notepad++ or the Notepad application.

◆ GetListenConfigList()

std::vector< ListenPortConfig > util::log::GetListenConfigList ( )
nodiscard

Returns a list of available listen servers on the computer.

Returns
List of listen servers.

◆ ProgramDataPath()

std::string util::log::ProgramDataPath ( )

Utility function that returns the default program data path

Returns
Typical 'c:/programdata' in Windows.