Basic Logger.  
More...
#include <stdio.h>
#include <stdarg.h>
#include "apt.h"
 
Go to the source code of this file.
 | 
| 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
 } | 
|   | 
| enum   | apt_log_masking_e { APT_LOG_MASKING_NONE, 
APT_LOG_MASKING_COMPLETE, 
APT_LOG_MASKING_ENCRYPTED
 } | 
|   | 
 | 
| 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_t *  | apt_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_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) | 
|   | 
Default log mark providing log source, file and line information 
 
 
      
        
          | #define APT_LOG_MARK_DECLARE | 
          ( | 
            | 
          LOG_SOURCE | ) | 
             LOG_SOURCE,__FILE__,__LINE__ | 
        
      
 
Declaration of log mark to be used by custom log sources 
 
 
      
        
          | #define APT_LOG_SOURCE_DECLARE | 
          ( | 
            | 
          SCOPE,  | 
        
        
           | 
           | 
            | 
          LOG_SOURCE  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Value:
    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 
 
 
      
        
          | #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
 
 Use this macro in a source file to implement a custom log source 
 
 
      
        
          | #define APT_NAMESID_FMT   "%s " APT_SID_FMT | 
        
      
 
Format to log names and identifiers 
 
 
      
        
          | #define APT_NAMESIDRES_FMT   "%s " APT_SIDRES_FMT | 
        
      
 
Format to log names, identifiers and resources 
 
 
      
        
          | #define APT_PTR_FMT   "0x%lx" | 
        
      
 
Format to log pointer values 
 
 
Format to log pointers and identifiers 
 
 
      
        
          | #define APT_SID_FMT   "<%s>" | 
        
      
 
Format to log string identifiers 
 
 
      
        
          | #define APT_SIDRES_FMT   "<%s@%s>" | 
        
      
 
Format to log string identifiers and resources 
 
 
      
        
          | #define MAX_LOG_FILE_COUNT   100 | 
        
      
 
Default max number of log files used in rotation 
 
 
      
        
          | #define MAX_LOG_FILE_SIZE   (8 * 1024 * 1024) | 
        
      
 
Default max size of the log file (8Mb) 
 
 
      
        
          | 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 
 
 
Opaque log source declaration 
 
 
Opaque logger declaration 
 
 
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  
 | 
 
 
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  
 | 
 
 
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  
 | 
 
 
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  
 | 
 
 
Set the default log source. 
- Parameters
 - 
  
    | log_source | the log source to set  | 
  
   
 
 
Do logging. 
- Parameters
 - 
  
    | log_source | the log source  | 
    | file | the file name log entry is generated from  | 
    | line | the line number log entry is generated from  | 
    | priority | the priority of the entire log entry  | 
    | format | the format of the entire log entry  | 
  
   
 
 
      
        
          | 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_in | the data to mask  | 
    | length | the length of the data to mask on input, the length of the masked data on output  | 
    | pool | the memory pool to use if needed  | 
  
   
- Returns
 - The masked data. 
 
 
 
Set the extended external log handler. 
- Parameters
 - 
  
    | handler | the handler to pass log events to  | 
  
   
 
 
      
        
          | 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_path | the path to the log directory  | 
    | file_name | the name of the log file  | 
    | max_file_size | the max size of the log file  | 
    | max_file_count | the max number of files used in log rotation  | 
    | append | whether to append or to truncate (start over) the log file  | 
    | pool | the memory pool to use  | 
  
   
 
 
Set the header (format) for log messages. 
- Parameters
 - 
  
    | header | the header to set (used as bitmask)  | 
  
   
 
 
      
        
          | int apt_log_header_translate  | 
          ( | 
          char *  | 
          str | ) | 
           | 
        
      
 
Translate the header string to bitmask of apt_log_header_e values. 
- Parameters
 - 
  
    | str | the string to translate  | 
  
   
 
 
Create the singleton instance of the logger. 
- Parameters
 - 
  
    | mode | the log output mode  | 
    | priority | the log priority level  | 
    | pool | the memory pool to use  | 
  
   
 
 
Destroy the singleton instance of the logger. 
 
 
Get the singleton instance of the logger. 
 
 
      
        
          | 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_file | the path to configuration file to load settings from  | 
    | pool | the memory pool to use  | 
  
   
 
 
Set the singleton instance of the logger. 
- Parameters
 - 
  
  
 
 
 
Get the current masking mode of private data. 
 
 
Set the masking mode of private data. 
- Parameters
 - 
  
    | masking | the masking mode to set  | 
  
   
 
 
Translate the masking mode string to enum. 
- Parameters
 - 
  
    | str | the string to translate  | 
  
   
 
 
Check the logging output mode to be enabled (set) or not. 
- Parameters
 - 
  
  
 
 
 
Set the logging output mode. 
- Parameters
 - 
  
  
 
 
 
      
        
          | int apt_log_output_mode_translate  | 
          ( | 
          char *  | 
          str | ) | 
           | 
        
      
 
Translate the output mode string to bitmask of apt_log_output_e values. 
- Parameters
 - 
  
    | str | the string to translate  | 
  
   
 
 
Set the logging priority (log level). 
- Parameters
 - 
  
    | priority | the priority to set  | 
  
   
 
 
Translate the priority (log level) string to enum. 
- Parameters
 - 
  
    | str | the string to translate  | 
  
   
 
 
Find and assign log source by its name. 
- Parameters
 - 
  
    | name | the unique name associated to the log source  | 
    | log_source | the log source to be returned, if found  | 
  
   
 
 
Do logging (this version uses an object externally associated with the logger). 
- Parameters
 - 
  
    | log_source | the log source  | 
    | file | the file name log entry is generated from  | 
    | line | the line number log entry is generated from  | 
    | priority | the priority of the entire log entry  | 
    | obj | the associated object  | 
    | format | the format of the entire log entry  | 
  
   
 
 
Do logging (this version accepts va_list argument). 
- Parameters
 - 
  
    | log_source | the log source  | 
    | file | the file name log entry is generated from  | 
    | line | the line number log entry is generated from  | 
    | priority | the priority of the entire log entry  | 
    | format | the format of the entire log entry  | 
    | arg_ptr | the arguments  | 
  
   
 
 
Default (globally available) log source