UniMRCP  1.7.0
Macros | Typedefs | Enumerations | Functions | Variables
apt_log.h File Reference

Basic Logger. More...

#include <stdio.h>
#include <stdarg.h>
#include "apt.h"
Include dependency graph for apt_log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAX_LOG_FILE_SIZE   (8 * 1024 * 1024)
 
#define MAX_LOG_FILE_COUNT   100
 
#define APT_LOG_MARK_DECLARE(LOG_SOURCE)   LOG_SOURCE,__FILE__,__LINE__
 
#define APT_LOG_SOURCE_DECLARE(SCOPE, LOG_SOURCE)
 
#define APT_LOG_SOURCE_IMPLEMENT(SCOPE, LOG_SOURCE, LOG_SOURCE_TAG)
 
#define APT_LOG_MARK   APT_LOG_MARK_DECLARE(&def_log_source)
 
#define APT_PTR_FMT   "0x%lx"
 
#define APT_SID_FMT   "<%s>"
 
#define APT_SIDRES_FMT   "<%s@%s>"
 
#define APT_PTRSID_FMT   APT_PTR_FMT " " APT_SID_FMT
 
#define APT_NAMESID_FMT   "%s " APT_SID_FMT
 
#define APT_NAMESIDRES_FMT   "%s " APT_SIDRES_FMT
 

Typedefs

typedef struct apt_log_source_t apt_log_source_t
 
typedef struct apt_logger_t apt_logger_t
 
typedef apt_bool_t(* apt_log_ext_handler_f) (const char *file, int line, const char *obj, apt_log_priority_e priority, const char *format, va_list arg_ptr)
 

Enumerations

enum  apt_log_priority_e {
  APT_PRIO_EMERGENCY, APT_PRIO_ALERT, APT_PRIO_CRITICAL, APT_PRIO_ERROR,
  APT_PRIO_WARNING, APT_PRIO_NOTICE, APT_PRIO_INFO, APT_PRIO_DEBUG,
  APT_PRIO_COUNT
}
 
enum  apt_log_header_e {
  APT_LOG_HEADER_NONE = 0x00, APT_LOG_HEADER_DATE = 0x01, APT_LOG_HEADER_TIME = 0x02, APT_LOG_HEADER_PRIORITY = 0x04,
  APT_LOG_HEADER_MARK = 0x08, APT_LOG_HEADER_THREAD = 0x10, APT_LOG_HEADER_DEFAULT = APT_LOG_HEADER_DATE | APT_LOG_HEADER_TIME | APT_LOG_HEADER_PRIORITY
}
 
enum  apt_log_output_e { APT_LOG_OUTPUT_NONE = 0x00, APT_LOG_OUTPUT_CONSOLE = 0x01, APT_LOG_OUTPUT_FILE = 0x02, APT_LOG_OUTPUT_SYSLOG = 0x04 }
 
enum  apt_log_masking_e { APT_LOG_MASKING_NONE, APT_LOG_MASKING_COMPLETE, APT_LOG_MASKING_ENCRYPTED }
 

Functions

apt_bool_t apt_log_instance_create (apt_log_output_e mode, apt_log_priority_e priority, apr_pool_t *pool)
 
apt_bool_t apt_log_instance_load (const char *config_file, apr_pool_t *pool)
 
apt_bool_t apt_log_instance_destroy (void)
 
apt_logger_tapt_log_instance_get (void)
 
apt_bool_t apt_log_instance_set (apt_logger_t *logger)
 
void apt_def_log_source_set (apt_log_source_t *log_source)
 
apt_bool_t apt_log_source_assign (const char *name, apt_log_source_t **log_source)
 
apt_bool_t apt_log_file_open (const char *dir_path, const char *file_name, apr_size_t max_file_size, apr_size_t max_file_count, apt_bool_t append, apr_pool_t *pool)
 
apt_bool_t apt_log_file_open_ex (const char *dir_path, const char *prefix, const char *config_file, apr_pool_t *pool)
 
apt_bool_t apt_log_file_close (void)
 
apt_bool_t apt_syslog_open (const char *prefix, const char *config_file, apr_pool_t *pool)
 
apt_bool_t apt_syslog_close (void)
 
apt_bool_t apt_log_output_mode_set (apt_log_output_e mode)
 
apt_bool_t apt_log_output_mode_check (apt_log_output_e mode)
 
int apt_log_output_mode_translate (char *str)
 
apt_bool_t apt_log_priority_set (apt_log_priority_e priority)
 
apt_log_priority_e apt_log_priority_translate (const char *str)
 
apt_bool_t apt_log_header_set (int header)
 
int apt_log_header_translate (char *str)
 
apt_bool_t apt_log_masking_set (apt_log_masking_e masking)
 
apt_log_masking_e apt_log_masking_get (void)
 
apt_log_masking_e apt_log_masking_translate (const char *str)
 
const char * apt_log_data_mask (const char *data_in, apr_size_t *length, apr_pool_t *pool)
 
apt_bool_t apt_log_ext_handler_set (apt_log_ext_handler_f handler)
 
apt_bool_t apt_log (apt_log_source_t *log_source, const char *file, int line, apt_log_priority_e priority, const char *format,...)
 
apt_bool_t apt_obj_log (apt_log_source_t *log_source, const char *file, int line, apt_log_priority_e priority, void *obj, const char *format,...)
 
apt_bool_t apt_va_log (apt_log_source_t *log_source, const char *file, int line, apt_log_priority_e priority, const char *format, va_list arg_ptr)
 

Variables

apt_log_source_t def_log_source
 

Detailed Description

Basic Logger.

Macro Definition Documentation

◆ APT_LOG_MARK

#define APT_LOG_MARK   APT_LOG_MARK_DECLARE(&def_log_source)

Default log mark providing log source, file and line information

◆ APT_LOG_MARK_DECLARE

#define APT_LOG_MARK_DECLARE (   LOG_SOURCE)    LOG_SOURCE,__FILE__,__LINE__

Declaration of log mark to be used by custom log sources

◆ APT_LOG_SOURCE_DECLARE

#define APT_LOG_SOURCE_DECLARE (   SCOPE,
  LOG_SOURCE 
)
Value:
extern apt_log_source_t *LOG_SOURCE; \
SCOPE##_DECLARE(void) LOG_SOURCE##_init();
struct apt_log_source_t apt_log_source_t
Definition: apt_log.h:37

Use this macro in a header file to declare a custom log source

◆ APT_LOG_SOURCE_IMPLEMENT

#define APT_LOG_SOURCE_IMPLEMENT (   SCOPE,
  LOG_SOURCE,
  LOG_SOURCE_TAG 
)
Value:
SCOPE##_DECLARE(void) LOG_SOURCE##_init() {apt_log_source_assign(LOG_SOURCE_TAG,&LOG_SOURCE);}
apt_log_source_t def_log_source
struct apt_log_source_t apt_log_source_t
Definition: apt_log.h:37
apt_bool_t apt_log_source_assign(const char *name, apt_log_source_t **log_source)

Use this macro in a source file to implement a custom log source

◆ APT_NAMESID_FMT

#define APT_NAMESID_FMT   "%s " APT_SID_FMT

Format to log names and identifiers

◆ APT_NAMESIDRES_FMT

#define APT_NAMESIDRES_FMT   "%s " APT_SIDRES_FMT

Format to log names, identifiers and resources

◆ APT_PTR_FMT

#define APT_PTR_FMT   "0x%lx"

Format to log pointer values

◆ APT_PTRSID_FMT

#define APT_PTRSID_FMT   APT_PTR_FMT " " APT_SID_FMT

Format to log pointers and identifiers

◆ APT_SID_FMT

#define APT_SID_FMT   "<%s>"

Format to log string identifiers

◆ APT_SIDRES_FMT

#define APT_SIDRES_FMT   "<%s@%s>"

Format to log string identifiers and resources

◆ MAX_LOG_FILE_COUNT

#define MAX_LOG_FILE_COUNT   100

Default max number of log files used in rotation

◆ MAX_LOG_FILE_SIZE

#define MAX_LOG_FILE_SIZE   (8 * 1024 * 1024)

Default max size of the log file (8Mb)

Typedef Documentation

◆ apt_log_ext_handler_f

typedef apt_bool_t(* apt_log_ext_handler_f) (const char *file, int line, const char *obj, apt_log_priority_e priority, const char *format, va_list arg_ptr)

Prototype of extended log handler function

◆ apt_log_source_t

Opaque log source declaration

◆ apt_logger_t

typedef struct apt_logger_t apt_logger_t

Opaque logger declaration

Enumeration Type Documentation

◆ apt_log_header_e

Header (format) of log messages

Enumerator
APT_LOG_HEADER_NONE 

disable optional headers output

APT_LOG_HEADER_DATE 

enable date output

APT_LOG_HEADER_TIME 

enable time output

APT_LOG_HEADER_PRIORITY 

enable priority name output

APT_LOG_HEADER_MARK 

enable file:line mark output

APT_LOG_HEADER_THREAD 

enable thread identifier output

◆ apt_log_masking_e

Masking mode of private data

Enumerator
APT_LOG_MASKING_NONE 

log everything as is

APT_LOG_MASKING_COMPLETE 

mask private data completely

APT_LOG_MASKING_ENCRYPTED 

encrypt private data

◆ apt_log_output_e

Mode of log output

Enumerator
APT_LOG_OUTPUT_NONE 

disable logging

APT_LOG_OUTPUT_CONSOLE 

enable console output

APT_LOG_OUTPUT_FILE 

enable log file output

APT_LOG_OUTPUT_SYSLOG 

enable syslog output

◆ apt_log_priority_e

Priority of log messages ordered from highest priority to lowest (rfc3164)

Enumerator
APT_PRIO_EMERGENCY 

system is unusable

APT_PRIO_ALERT 

action must be taken immediately

APT_PRIO_CRITICAL 

critical condition

APT_PRIO_ERROR 

error condition

APT_PRIO_WARNING 

warning condition

APT_PRIO_NOTICE 

normal, but significant condition

APT_PRIO_INFO 

informational message

APT_PRIO_DEBUG 

debug-level message

APT_PRIO_COUNT 

number of priorities

Function Documentation

◆ apt_def_log_source_set()

void apt_def_log_source_set ( apt_log_source_t log_source)

Set the default log source.

Parameters
log_sourcethe log source to set

◆ apt_log()

apt_bool_t apt_log ( apt_log_source_t log_source,
const char *  file,
int  line,
apt_log_priority_e  priority,
const char *  format,
  ... 
)

Do logging.

Parameters
log_sourcethe log source
filethe file name log entry is generated from
linethe line number log entry is generated from
prioritythe priority of the entire log entry
formatthe format of the entire log entry

◆ apt_log_data_mask()

const char* apt_log_data_mask ( const char *  data_in,
apr_size_t *  length,
apr_pool_t *  pool 
)

Mask private data based on the masking mode.

Parameters
data_inthe data to mask
lengththe length of the data to mask on input, the length of the masked data on output
poolthe memory pool to use if needed
Returns
The masked data.

◆ apt_log_ext_handler_set()

apt_bool_t apt_log_ext_handler_set ( apt_log_ext_handler_f  handler)

Set the extended external log handler.

Parameters
handlerthe handler to pass log events to
Remarks
default logger is used to output the logs to stdout and/or log file, if external log handler isn't set

◆ apt_log_file_close()

apt_bool_t apt_log_file_close ( void  )

Close the log file.

◆ apt_log_file_open()

apt_bool_t apt_log_file_open ( const char *  dir_path,
const char *  file_name,
apr_size_t  max_file_size,
apr_size_t  max_file_count,
apt_bool_t  append,
apr_pool_t *  pool 
)

Open the log file.

Parameters
dir_paththe path to the log directory
file_namethe name of the log file
max_file_sizethe max size of the log file
max_file_countthe max number of files used in log rotation
appendwhether to append or to truncate (start over) the log file
poolthe memory pool to use
Deprecated:
See also
apt_log_file_open_ex()

◆ apt_log_file_open_ex()

apt_bool_t apt_log_file_open_ex ( const char *  dir_path,
const char *  prefix,
const char *  config_file,
apr_pool_t *  pool 
)

Open the log file (extended version).

Parameters
dir_paththe path to the log directory
prefixthe prefix used to compose the log file name
config_filethe path to configuration file to load settings from
poolthe memory pool to use

◆ apt_log_header_set()

apt_bool_t apt_log_header_set ( int  header)

Set the header (format) for log messages.

Parameters
headerthe header to set (used as bitmask)

◆ apt_log_header_translate()

int apt_log_header_translate ( char *  str)

Translate the header string to bitmask of apt_log_header_e values.

Parameters
strthe string to translate

◆ apt_log_instance_create()

apt_bool_t apt_log_instance_create ( apt_log_output_e  mode,
apt_log_priority_e  priority,
apr_pool_t *  pool 
)

Create the singleton instance of the logger.

Parameters
modethe log output mode
prioritythe log priority level
poolthe memory pool to use

◆ apt_log_instance_destroy()

apt_bool_t apt_log_instance_destroy ( void  )

Destroy the singleton instance of the logger.

◆ apt_log_instance_get()

apt_logger_t* apt_log_instance_get ( void  )

Get the singleton instance of the logger.

◆ apt_log_instance_load()

apt_bool_t apt_log_instance_load ( const char *  config_file,
apr_pool_t *  pool 
)

Create and load the singleton instance of the logger.

Parameters
config_filethe path to configuration file to load settings from
poolthe memory pool to use

◆ apt_log_instance_set()

apt_bool_t apt_log_instance_set ( apt_logger_t logger)

Set the singleton instance of the logger.

Parameters
loggerthe logger to set

◆ apt_log_masking_get()

apt_log_masking_e apt_log_masking_get ( void  )

Get the current masking mode of private data.

◆ apt_log_masking_set()

apt_bool_t apt_log_masking_set ( apt_log_masking_e  masking)

Set the masking mode of private data.

Parameters
maskingthe masking mode to set

◆ apt_log_masking_translate()

apt_log_masking_e apt_log_masking_translate ( const char *  str)

Translate the masking mode string to enum.

Parameters
strthe string to translate

◆ apt_log_output_mode_check()

apt_bool_t apt_log_output_mode_check ( apt_log_output_e  mode)

Check the logging output mode to be enabled (set) or not.

Parameters
modethe mode to check

◆ apt_log_output_mode_set()

apt_bool_t apt_log_output_mode_set ( apt_log_output_e  mode)

Set the logging output mode.

Parameters
modethe mode to set

◆ apt_log_output_mode_translate()

int apt_log_output_mode_translate ( char *  str)

Translate the output mode string to bitmask of apt_log_output_e values.

Parameters
strthe string to translate

◆ apt_log_priority_set()

apt_bool_t apt_log_priority_set ( apt_log_priority_e  priority)

Set the logging priority (log level).

Parameters
prioritythe priority to set

◆ apt_log_priority_translate()

apt_log_priority_e apt_log_priority_translate ( const char *  str)

Translate the priority (log level) string to enum.

Parameters
strthe string to translate

◆ apt_log_source_assign()

apt_bool_t apt_log_source_assign ( const char *  name,
apt_log_source_t **  log_source 
)

Find and assign log source by its name.

Parameters
namethe unique name associated to the log source
log_sourcethe log source to be returned, if found

◆ apt_obj_log()

apt_bool_t apt_obj_log ( apt_log_source_t log_source,
const char *  file,
int  line,
apt_log_priority_e  priority,
void *  obj,
const char *  format,
  ... 
)

Do logging (this version uses an object externally associated with the logger).

Parameters
log_sourcethe log source
filethe file name log entry is generated from
linethe line number log entry is generated from
prioritythe priority of the entire log entry
objthe associated object
formatthe format of the entire log entry

◆ apt_syslog_close()

apt_bool_t apt_syslog_close ( void  )

Close the syslog.

◆ apt_syslog_open()

apt_bool_t apt_syslog_open ( const char *  prefix,
const char *  config_file,
apr_pool_t *  pool 
)

Open the syslog.

Parameters
prefixthe prefix used to compose the log file name
config_filethe path to configuration file to load settings from
poolthe memory pool to use

◆ apt_va_log()

apt_bool_t apt_va_log ( apt_log_source_t log_source,
const char *  file,
int  line,
apt_log_priority_e  priority,
const char *  format,
va_list  arg_ptr 
)

Do logging (this version accepts va_list argument).

Parameters
log_sourcethe log source
filethe file name log entry is generated from
linethe line number log entry is generated from
prioritythe priority of the entire log entry
formatthe format of the entire log entry
arg_ptrthe arguments

Variable Documentation

◆ def_log_source

apt_log_source_t def_log_source

Default (globally available) log source