Diag-Client-Lib
Public Member Functions | Private Member Functions | Private Attributes | List of all members
utility::logger::Logger Class Referencefinal

Logger class that is used to log Dlt messages from the component. More...

#include <logger.h>

Public Member Functions

template<typename Func >
auto LogFatal (const std::string_view file_name, int line_no, const std::string_view func_name, Func &&func) noexcept -> void
 Log fatal message and abort. More...
 
template<typename Func >
auto LogError (const std::string_view file_name, int line_no, const std::string_view func_name, Func &&func) noexcept -> void
 Log error message. More...
 
template<typename Func >
auto LogWarn (const std::string_view file_name, int line_no, const std::string_view func_name, Func &&func) noexcept -> void
 Log warning message. More...
 
template<typename Func >
auto LogInfo (const std::string_view file_name, int line_no, const std::string_view func_name, Func &&func) noexcept -> void
 Log info message. More...
 
template<typename Func >
auto LogDebug (const std::string_view file_name, int line_no, const std::string_view func_name, Func &&func) noexcept -> void
 Log debug message. More...
 
template<typename Func >
auto LogVerbose (const std::string_view file_name, int line_no, const std::string_view func_name, Func &&func) noexcept -> void
 Log verbose message. More...
 
 Logger (std::string_view context_id)
 Construct an instance of Logger. More...
 
 Logger (std::string_view app_id, std::string_view context_id)
 Construct an instance of Logger. More...
 
 ~Logger ()
 Destruct an instance of Logger. More...
 

Private Member Functions

template<typename Func >
auto CreateLoggingMessage (const std::string_view file_name, const std::string_view, int line_no, Func &&func) noexcept -> std::stringstream
 Function to create the final logging message. More...
 

Private Attributes

std::string contxt_
 Function to send the messages to dlt infrastructure. More...
 
std::string app_id_
 
std::string context_id_
 
bool registration_with_app_id_ {}
 

Detailed Description

Logger class that is used to log Dlt messages from the component.

This class uses COVESA DLT infrastructure to send message to DLT. Also the class does not log dlt message if "ENABLE_DLT_LOGGER" cmake flag is set to OFF

Definition at line 32 of file logger.h.

Constructor & Destructor Documentation

◆ Logger() [1/2]

utility::logger::Logger::Logger ( std::string_view  context_id)
explicit

Construct an instance of Logger.

Parameters
[in]context_idThe context id of the user

Definition at line 14 of file logger.cpp.

15  : contxt_{},
16  app_id_{},
17  context_id_{context_id},
19 #ifdef ENABLE_DLT_LOGGER
20  DLT_REGISTER_CONTEXT(contxt_, context_id_.c_str(), "Application Context");
21 #else
23 #endif
24 }
std::string app_id_
Definition: logger.h:266
bool registration_with_app_id_
Definition: logger.h:272
std::string context_id_
Definition: logger.h:269
std::string contxt_
Function to send the messages to dlt infrastructure.
Definition: logger.h:263
#define UNUSED_PARAM(expr)
Definition: logger.h:21

References context_id_, contxt_, registration_with_app_id_, and UNUSED_PARAM.

◆ Logger() [2/2]

utility::logger::Logger::Logger ( std::string_view  app_id,
std::string_view  context_id 
)

Construct an instance of Logger.

Parameters
[in]app_idThe application id of the user
[in]context_idThe context id of the user

Definition at line 26 of file logger.cpp.

27  : contxt_{},
28  app_id_{app_id},
29  context_id_{context_id},
31 #ifdef ENABLE_DLT_LOGGER
32  DLT_REGISTER_APP(app_id_.c_str(), "Application Id");
33  DLT_REGISTER_CONTEXT(contxt_, context_id_.c_str(), "Application Context");
34 #else
36 #endif
37 }

References app_id_, context_id_, contxt_, registration_with_app_id_, and UNUSED_PARAM.

◆ ~Logger()

utility::logger::Logger::~Logger ( )

Destruct an instance of Logger.

Definition at line 39 of file logger.cpp.

39  {
40 #ifdef ENABLE_DLT_LOGGER
41  DLT_UNREGISTER_CONTEXT(contxt_);
42  if (registration_with_app_id_) { DLT_UNREGISTER_APP(); }
43 #endif
44 }

References contxt_, and registration_with_app_id_.

Member Function Documentation

◆ CreateLoggingMessage()

template<typename Func >
auto utility::logger::Logger::CreateLoggingMessage ( const std::string_view  file_name,
const std::string_view  ,
int  line_no,
Func &&  func 
) -> std::stringstream
inlineprivatenoexcept

Function to create the final logging message.

Template Parameters
FuncThe functor type
Parameters
[in]file_nameThe file name
[in]func_nameThe function name
[in]line_noThe line number
[in]funcThe functor which gets invoked

Definition at line 228 of file logger.h.

229  {
230  std::stringstream msg{};
231  func(msg);
232  msg << " [" << file_name << ":" << line_no << "]";
233  return msg;
234  }

◆ LogDebug()

template<typename Func >
auto utility::logger::Logger::LogDebug ( const std::string_view  file_name,
int  line_no,
const std::string_view  func_name,
Func &&  func 
) -> void
inlinenoexcept

Log debug message.

Template Parameters
FuncThe functor type invoked on log level set to debug
Parameters
[in]file_nameThe file name
[in]line_noThe line number
[in]func_nameThe function name
[in]funcThe functor which gets invoked on log level set to debug

Definition at line 153 of file logger.h.

154  {
155 #ifdef ENABLE_DLT_LOGGER
156  LogDltMessage(DLT_LOG_DEBUG, file_name, func_name, line_no, std::forward<Func>(func));
157 #else
158  UNUSED_PARAM(file_name);
159  UNUSED_PARAM(line_no);
160  UNUSED_PARAM(func_name);
161  UNUSED_PARAM(func);
162 #endif
163  }

References UNUSED_PARAM.

◆ LogError()

template<typename Func >
auto utility::logger::Logger::LogError ( const std::string_view  file_name,
int  line_no,
const std::string_view  func_name,
Func &&  func 
) -> void
inlinenoexcept

Log error message.

Template Parameters
FuncThe functor type invoked on log level set to error
Parameters
[in]file_nameThe file name
[in]line_noThe line number
[in]func_nameThe function name
[in]funcThe functor which gets invoked on log level set to error

Definition at line 75 of file logger.h.

76  {
77 #ifdef ENABLE_DLT_LOGGER
78  LogDltMessage(DLT_LOG_ERROR, file_name, func_name, line_no, std::forward<Func>(func));
79 #else
80  UNUSED_PARAM(file_name);
81  UNUSED_PARAM(line_no);
82  UNUSED_PARAM(func_name);
83  UNUSED_PARAM(func);
84 #endif
85  }

References UNUSED_PARAM.

◆ LogFatal()

template<typename Func >
auto utility::logger::Logger::LogFatal ( const std::string_view  file_name,
int  line_no,
const std::string_view  func_name,
Func &&  func 
) -> void
inlinenoexcept

Log fatal message and abort.

Template Parameters
FuncThe functor type invoked on log level set to fatal
Parameters
[in]file_nameThe file name
[in]line_noThe line number
[in]func_nameThe function name
[in]funcThe functor which gets invoked on log level set to fatal

Definition at line 48 of file logger.h.

49  {
50 #ifdef ENABLE_DLT_LOGGER
51  LogDltMessage(DLT_LOG_FATAL, file_name, func_name, line_no, std::forward<Func>(func));
52 #else
53  UNUSED_PARAM(file_name);
54  UNUSED_PARAM(line_no);
55  UNUSED_PARAM(func_name);
56  UNUSED_PARAM(func);
57 #endif
58  std::abort(); // abort in case of fatal issue
59  }

References UNUSED_PARAM.

◆ LogInfo()

template<typename Func >
auto utility::logger::Logger::LogInfo ( const std::string_view  file_name,
int  line_no,
const std::string_view  func_name,
Func &&  func 
) -> void
inlinenoexcept

Log info message.

Template Parameters
FuncThe functor type invoked on log level set to info
Parameters
[in]file_nameThe file name
[in]line_noThe line number
[in]func_nameThe function name
[in]funcThe functor which gets invoked on log level set to info

Definition at line 127 of file logger.h.

128  {
129 #ifdef ENABLE_DLT_LOGGER
130  LogDltMessage(DLT_LOG_INFO, file_name, func_name, line_no, std::forward<Func>(func));
131 #else
132  UNUSED_PARAM(file_name);
133  UNUSED_PARAM(line_no);
134  UNUSED_PARAM(func_name);
135  UNUSED_PARAM(func);
136 #endif
137  }

References UNUSED_PARAM.

◆ LogVerbose()

template<typename Func >
auto utility::logger::Logger::LogVerbose ( const std::string_view  file_name,
int  line_no,
const std::string_view  func_name,
Func &&  func 
) -> void
inlinenoexcept

Log verbose message.

Template Parameters
FuncThe functor type invoked on log level set to verbose
Parameters
[in]file_nameThe file name
[in]line_noThe line number
[in]func_nameThe function name
[in]funcThe functor which gets invoked on log level set to verbose

Definition at line 179 of file logger.h.

180  {
181 #ifdef ENABLE_DLT_LOGGER
182  LogDltMessage(DLT_LOG_VERBOSE, file_name, func_name, line_no, std::forward<Func>(func));
183 #else
184  UNUSED_PARAM(file_name);
185  UNUSED_PARAM(line_no);
186  UNUSED_PARAM(func_name);
187  UNUSED_PARAM(func);
188 #endif
189  }

References UNUSED_PARAM.

◆ LogWarn()

template<typename Func >
auto utility::logger::Logger::LogWarn ( const std::string_view  file_name,
int  line_no,
const std::string_view  func_name,
Func &&  func 
) -> void
inlinenoexcept

Log warning message.

Template Parameters
FuncThe functor type invoked on log level set to warning
Parameters
[in]file_nameThe file name
[in]line_noThe line number
[in]func_nameThe function name
[in]funcThe functor which gets invoked on log level set to warning

Definition at line 101 of file logger.h.

102  {
103 #ifdef ENABLE_DLT_LOGGER
104  LogDltMessage(DLT_LOG_WARN, file_name, func_name, line_no, std::forward<Func>(func));
105 #else
106  UNUSED_PARAM(file_name);
107  UNUSED_PARAM(line_no);
108  UNUSED_PARAM(func_name);
109  UNUSED_PARAM(func);
110 #endif
111  }

References UNUSED_PARAM.

Member Data Documentation

◆ app_id_

std::string utility::logger::Logger::app_id_
private

Definition at line 266 of file logger.h.

Referenced by Logger().

◆ context_id_

std::string utility::logger::Logger::context_id_
private

Definition at line 269 of file logger.h.

Referenced by Logger().

◆ contxt_

std::string utility::logger::Logger::contxt_
private

Function to send the messages to dlt infrastructure.

Template Parameters
log_levelThe log level
Parameters
[in]file_nameThe file name
[in]func_nameThe function name
[in]line_noThe line number
[in]funcThe functor which gets invoked

Definition at line 263 of file logger.h.

Referenced by Logger(), and ~Logger().

◆ registration_with_app_id_

bool utility::logger::Logger::registration_with_app_id_ {}
private

Definition at line 272 of file logger.h.

Referenced by Logger(), and ~Logger().


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