OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL > Class Template Reference

#include <logger.hpp>

Public Member Functions

int log_level () const
 return the current logging level for all logging
 
void set_log_level (int level)
 set the log level for all loggigng
 
std::string log_prefix () const
 return the current prefix all logging
 
void set_log_prefix (const std::string &prefix)
 set the log prefix for all loggigng
 
template<int LEVEL, typename T >
void log (T &&msg) const
 
template<typename T >
void log_trace (T &&msg) const
 
template<typename T >
void log_debug (T &&msg) const
 
template<typename T >
void log_info (T &&msg) const
 
template<typename T >
void log_verbose (T &&msg) const
 
template<typename T >
void log_error (T &&msg) const
 

Static Public Attributes

static constexpr int max_log_level = std::max(MAX_LEVEL, DEFAULT_LOG_LEVEL)
 
static constexpr int default_log_level = DEFAULT_LOG_LEVEL
 

Protected Attributes

int current_log_level = DEFAULT_LOG_LEVEL
 configured loglevel
 
std::string prefix_
 

Detailed Description

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
class openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >

A class that simplifies the logging with different verbosity. It is intended to be either used as a base class or preferably as a member. The member can be either a normal member or static member depending if setting the loglevel should affect all instances of the class or only the current one.

e.g.:

 static inline logging::Logger<logging::LOG_LEVEL_INFO, logging::LOG_LEVEL_VERB> log_;

and then when logging in the class use

Template Parameters
DEFAULT_LOG_LEVELthe default loglevel for this class
MAX_LEVELthe maximum loglevel that will be printed. Logging with higher verbosity will be disabled by using if constexpr expressions. Will be ignored and set to DEFAULT_LOG_LEVEL if DEFAULT_LOG_LEVEL is higher than MAX_LEVEL.

This allows to customise compile time maximum verbosity.

A mixin class that can be used as base class to expose the setting and getting of the log level publicly but not expose the log methods themselves. Class parameters are the same as for

Definition at line 53 of file logger.hpp.

Member Function Documentation

◆ log()

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
template<int LEVEL, typename T >
void openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::log ( T &&  msg) const
inline

Prints a log message for tracing if the log level is at least LEVEL.

Parameters
msgthe message to print

Definition at line 90 of file logger.hpp.

◆ log_debug()

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
template<typename T >
void openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::log_debug ( T &&  msg) const
inline

Prints a log message for debugging only info if the log level is at least DEBUG (=3)

Parameters
msgthe message to print

Definition at line 117 of file logger.hpp.

◆ log_error()

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
template<typename T >
void openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::log_error ( T &&  msg) const
inline

Logs an error message that should almost always be logged

Parameters
msgthe message to log

Definition at line 148 of file logger.hpp.

◆ log_info()

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
template<typename T >
void openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::log_info ( T &&  msg) const
inline

Prints a log message for general info if the log level is at least INFO (=1)

Parameters
msgthe message to print

Definition at line 128 of file logger.hpp.

◆ log_level()

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
int openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::log_level ( ) const
inline

return the current logging level for all logging

Definition at line 61 of file logger.hpp.

Here is the caller graph for this function:

◆ log_prefix()

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
std::string openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::log_prefix ( ) const
inline

return the current prefix all logging

Definition at line 73 of file logger.hpp.

◆ log_trace()

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
template<typename T >
void openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::log_trace ( T &&  msg) const
inline

Prints a log message for tracing if the log level is at least TRACE (=4)

Parameters
msgthe message to print

Definition at line 106 of file logger.hpp.

◆ log_verbose()

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
template<typename T >
void openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::log_verbose ( T &&  msg) const
inline

Prints a verbose log message if the log level is at least VERB (=2)

Parameters
msgthe message to log

Definition at line 138 of file logger.hpp.

◆ set_log_level()

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
void openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::set_log_level ( int  level)
inline

set the log level for all loggigng

Definition at line 67 of file logger.hpp.

Here is the caller graph for this function:

◆ set_log_prefix()

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
void openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::set_log_prefix ( const std::string &  prefix)
inline

set the log prefix for all loggigng

Definition at line 79 of file logger.hpp.

Member Data Documentation

◆ current_log_level

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
int openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::current_log_level = DEFAULT_LOG_LEVEL
protected

configured loglevel

Definition at line 155 of file logger.hpp.

◆ default_log_level

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
constexpr int openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::default_log_level = DEFAULT_LOG_LEVEL
staticconstexpr

Definition at line 57 of file logger.hpp.

◆ max_log_level

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
constexpr int openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::max_log_level = std::max(MAX_LEVEL, DEFAULT_LOG_LEVEL)
staticconstexpr

Definition at line 56 of file logger.hpp.

◆ prefix_

template<int DEFAULT_LOG_LEVEL, int MAX_LEVEL = LOG_LEVEL_DEBUG>
std::string openvpn::logging::Logger< DEFAULT_LOG_LEVEL, MAX_LEVEL >::prefix_
protected

Definition at line 156 of file logger.hpp.


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