CXI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Log Class Reference

Provides unified logging. More...

Public Types

enum  levels {
  LEVEL_NONE = 0 , LEVEL_ERROR , LEVEL_WARNING , LEVEL_INFO ,
  LEVEL_TRACE , LEVEL_DEBUG , LEVEL_NONE = 0 , LEVEL_ERROR ,
  LEVEL_WARNING , LEVEL_INFO , LEVEL_TRACE , LEVEL_DEBUG
}
 
enum  levels {
  LEVEL_NONE = 0 , LEVEL_ERROR , LEVEL_WARNING , LEVEL_INFO ,
  LEVEL_TRACE , LEVEL_DEBUG , LEVEL_NONE = 0 , LEVEL_ERROR ,
  LEVEL_WARNING , LEVEL_INFO , LEVEL_TRACE , LEVEL_DEBUG
}
 

Public Member Functions

 Log (char *filename=NULL, int level=Log::LEVEL_NONE, int size=0)
 
 Log (const Log &log)
 
 Log (Config &config)
 
void init (const char *filename=NULL, int level=Log::LEVEL_NONE, int size=0)
 
void init (Config &config)
 
void print (const char *where, const char *format,...)
 
void print (const char *where, int line, const char *format,...)
 
void xprint (const char *where, const char *text, const char *data, int len)
 
void xprint (const char *where, const char *text, const ByteArray &ba)
 

Static Public Member Functions

static LoggetInstance (void)
 

Detailed Description

Provides unified logging.

This class can be used in the following ways:

In the second case the log file contains log messages written by the application as well as the log messages written by the CXI API.

The following example illustrates the usage of the Log class:

// get reference to global log instance
// enable logging
log.init("cxi_demo.log", Log::LEVEL_INFO, 100000);
// log informational message (printed if level >= Log::LEVEL_INFO)
log.print("className::methodName", "I: module version: %c.%c\n", version.major, version.minor);
// log error message (printed if level >= Log::LEVEL_ERROR)
log.print("className::methodName", "E: function xy returned: 0x%08x", err);
// dump hexadecimal data
log.xprint("buffer", buffer, size);
Provides unified logging.
Definition: sw/cxi_api_c/def/log.h:33
void xprint(const char *where, const char *text, const char *data, int len)
Definition: log.cpp:539
void init(const char *filename=NULL, int level=Log::LEVEL_NONE, int size=0)
Definition: log.cpp:346
static Log & getInstance(void)
Definition: log.cpp:569
@ LEVEL_INFO
log errors, warnings and informational messages
Definition: sw/cxi_api_c/def/log.h:58
void print(const char *where, const char *format,...)
Definition: log.cpp:514

Member Enumeration Documentation

◆ levels [1/2]

enum levels

Log Level

Enumerator
LEVEL_NONE 

disable logging

LEVEL_ERROR 

log only errors

LEVEL_WARNING 

log errors and warnings

LEVEL_INFO 

log errors, warnings and informational messages

LEVEL_TRACE 

additionally log trace output (usually only for diagnostic purposes)

LEVEL_DEBUG 

additionally log debug output (usually only during development)

LEVEL_NONE 

disable logging

LEVEL_ERROR 

log only errors

LEVEL_WARNING 

log errors and warnings

LEVEL_INFO 

log errors, warnings and informational messages

LEVEL_TRACE 

additionally log trace output (usually only for diagnostic purposes)

LEVEL_DEBUG 

additionally log debug output (usually only during development)

◆ levels [2/2]

enum levels

Log Level

Enumerator
LEVEL_NONE 

disable logging

LEVEL_ERROR 

log only errors

LEVEL_WARNING 

log errors and warnings

LEVEL_INFO 

log errors, warnings and informational messages

LEVEL_TRACE 

additionally log trace output (usually only for diagnostic purposes)

LEVEL_DEBUG 

additionally log debug output (usually only during development)

LEVEL_NONE 

disable logging

LEVEL_ERROR 

log only errors

LEVEL_WARNING 

log errors and warnings

LEVEL_INFO 

log errors, warnings and informational messages

LEVEL_TRACE 

additionally log trace output (usually only for diagnostic purposes)

LEVEL_DEBUG 

additionally log debug output (usually only during development)

Constructor & Destructor Documentation

◆ Log() [1/3]

Log ( char *  filename = NULL,
int  level = Log::LEVEL_NONE,
int  size = 0 
)

Default Constructor

◆ Log() [2/3]

Log ( const Log log)

Copy Constructor: creates deep copy of instance

◆ Log() [3/3]

Log ( Config config)

Initializes log file according to the given configuration object.

Parameters
configConfiguration object. The following key names will be recognized:

Key Mandatory Default Value Description
LogFile No "" Filename (including path) of log file to be written. Use forward slashes as path separator (even on Windows).
LogLevel No LOG::LEVEL_NONE Log level to be applied, see Log::levels
LogSize No 1MB Maximum log file size before log file is rotated.
The integer value may optionally be followed by a tag ('KB', 'MB' or 'GB').
Note
If this value is configured as '0' log file may grow without limitation.


Member Function Documentation

◆ init() [1/2]

void init ( const char *  filename = NULL,
int  level = Log::LEVEL_NONE,
int  size = 0 
)

Initializes log file.

Parameters
filenamepath name of log file to be written.
levellog level (see Log::levels)
sizemaximum size of log file. If the actual log file size extends this limit the log file is renamed to *.bak and a new log file is created.
If the log size value is given as '0' the log file may grow without limitation.

◆ init() [2/2]

void init ( Config config)

Initializes log file according to the given configuration object.

Parameters
configConfiguration object. The following key names will be recognized:

Key Mandatory Default Value Description
LogFile No "" Filename (including path) of log file to be written. Use forward slashes as path separator (even on Windows).
LogLevel No LOG::LEVEL_NONE Log level to be applied, see Log::levels
LogSize No 1MB Maximum log file size before log file is rotated.
The integer value may optionally be followed by a tag ('KB', 'MB' or 'GB').
Note
If this value is configured as '0' log file may grow without limitation.


◆ print() [1/2]

void print ( const char *  where,
const char *  format,
  ... 
)

Adds string to log file.

Parameters
wherename of function or method, which generates log entry
formatformat specifier of variable argument list

◆ print() [2/2]

void print ( const char *  where,
int  line,
const char *  format,
  ... 
)

Adds a string to log file.

Parameters
wherename of function or method, which generates log entry
linenumber in source code
formatformat specifier of variable argument list

◆ xprint() [1/2]

void xprint ( const char *  where,
const char *  text,
const char *  data,
int  len 
)

Adds binary data to log file. The binary data is converted to hexadecimal notation.

Parameters
wherename of function, which generates log entry
texttag (optional)
datapointer to binary data
lenlength of binary data

◆ xprint() [2/2]

void xprint ( const char *  where,
const char *  text,
const ByteArray ba 
)

Adds binary data to log file. The binary data is converted to hexadecimal notation.

Parameters
wherename of function, which generates log entry
texttag (optional)
babyte array to be logged

◆ getInstance()

Log & getInstance ( void  )
static

Default log instance used to provide a unique log file for CXIAPI and application.
From your application you can enable logging as follows:
cxi::Log::getInstance().init(<filename>,<level>,<max_size>);