log.h File Reference

Macros

#define log_assert(x)   /*nothing*/
 an assertion that is thrown to the logfile.
 

Enumerations

enum  verbosity_value {
  NO_VERBOSE =0, NO_VERBOSE = 0, VERB_OPS, VERB_DETAIL,
  VERB_QUERY, VERB_ALGO, VERB_CLIENT
}
 verbosity value: More...
 

Functions

void verbose (enum verbosity_value level, const char *format,...) ATTR_FORMAT(printf
 log a verbose message, pass the level for this message. More...
 
void void log_init (const char *filename, int use_syslog, const char *chrootdir)
 call this to initialize logging services. More...
 
void log_file (FILE *f)
 Set logging to go to the specified file *. More...
 
void log_thread_set (int *num)
 Init a thread (will print this number for the thread log entries). More...
 
int log_thread_get (void)
 Get the thread id from logging system. More...
 
void log_ident_set (const char *id)
 Set identity to print, default is 'unbound'. More...
 
void log_ident_set_default (const char *id)
 Set default identity to print, default is 'unbound'. More...
 
void log_ident_revert_to_default (void)
 Revert identity to print, back to the recorded default value.
 
void log_ident_set_or_default (const char *identity)
 Set identity to print if there is an identity, otherwise set the default. More...
 
void log_set_time_asc (int use_asc)
 Set if the time value is printed ascii or decimal in log entries. More...
 
void * log_get_lock (void)
 get log lock
 
void log_info (const char *format,...) ATTR_FORMAT(printf
 Log informational message. More...
 
void void log_err (const char *format,...) ATTR_FORMAT(printf
 Log error message. More...
 
void void void log_warn (const char *format,...) ATTR_FORMAT(printf
 Log warning message. More...
 
void void void void log_hex (const char *msg, void *data, size_t length)
 Log a hex-string to the log. More...
 
void log_query (const char *format,...) ATTR_FORMAT(printf
 Log query. More...
 
void void log_reply (const char *format,...) ATTR_FORMAT(printf
 Log reply. More...
 
void void void log_buf (enum verbosity_value level, const char *msg, struct sldns_buffer *buf)
 Easy alternative for log_hex, takes a sldns_buffer. More...
 
void fatal_exit (const char *format,...) ATTR_FORMAT(printf
 Log fatal error message, and exit the current process. More...
 
void log_vmsg (int pri, const char *type, const char *format, va_list args)
 va_list argument version of log_info. More...
 

Variables

enum verbosity_value verbosity
 The global verbosity setting.
 
void ATTR_NORETURN
 

Detailed Description

This file contains logging functions.

Enumeration Type Documentation

◆ verbosity_value

verbosity value:

Enumerator
NO_VERBOSE 

0 - no verbose messages

VERB_OPS 

1 - operational information

VERB_DETAIL 

2 - detailed information

VERB_QUERY 

3 - query level information

VERB_ALGO 

4 - algorithm level information

VERB_CLIENT 

5 - querier client information

Function Documentation

◆ verbose()

void verbose ( enum verbosity_value  level,
const char *  format,
  ... 
)

log a verbose message, pass the level for this message.

It has printf formatted arguments. No trailing newline is needed.

Parameters
levelverbosity level for this message, compared to global verbosity setting.
formatprintf-style format string. Arguments follow.

◆ log_init()

void void log_init ( const char *  filename,
int  use_syslog,
const char *  chrootdir 
)

call this to initialize logging services.

Parameters
filenameif NULL stderr is used.
use_syslogset to true to ignore filename and use syslog(3).
chrootdirto which directory we have been chrooted, if any.

References ident, key_created, log_err(), log_lock, logfile, logkey, VERB_QUERY, and verbose().

Referenced by context_finalize(), do_log_reopen(), main(), service_start(), and ub_ctx_create_nopipe().

◆ log_file()

void log_file ( FILE *  f)

Set logging to go to the specified file *.

This setting does not affect the use_syslog setting.

Parameters
fto that file, or pass NULL to disable logging.

References log_lock, and logfile.

Referenced by context_finalize(), ub_ctx_debugout(), and ub_ctx_delete().

◆ log_thread_set()

void log_thread_set ( int *  num)

Init a thread (will print this number for the thread log entries).

Must be called from the thread itself. If not called 0 is printed.

Parameters
numnumber to print for this thread. Owned by caller, must continue to exist.

References logkey.

Referenced by daemon_cleanup(), dnstap_io(), ext_thread(), libworker_dobg(), test_thr_main(), and thread_start().

◆ log_thread_get()

int log_thread_get ( void  )

Get the thread id from logging system.

Set after log_init is initialised, or log_thread_set for newly created threads. This initialisation happens in unbound as a daemon, in daemon startup code, when that spawns threads.

Returns
thread number, from 0 and up. Before initialised, returns 0.

References key_created, and logkey.

◆ log_ident_set()

void log_ident_set ( const char *  id)

Set identity to print, default is 'unbound'.

Parameters
idstring to print. Name of executable.

References ident.

Referenced by log_ident_set_or_default(), main(), and ub_ctx_create_nopipe().

◆ log_ident_set_default()

void log_ident_set_default ( const char *  id)

Set default identity to print, default is 'unbound'.

Parameters
idstring to print. Name of executable.

Referenced by main().

◆ log_ident_set_or_default()

void log_ident_set_or_default ( const char *  identity)

Set identity to print if there is an identity, otherwise set the default.

Parameters
identitythe identity to set.

References log_ident_set().

Referenced by apply_settings().

◆ log_set_time_asc()

void log_set_time_asc ( int  use_asc)

Set if the time value is printed ascii or decimal in log entries.

Parameters
use_ascif true, ascii is printed, otherwise decimal. If the conversion fails or you have no time functions, decimal is printed.

References log_time_asc.

Referenced by config_apply(), and config_set_option().

◆ log_info()

void log_info ( const char *  format,
  ... 
)

Log informational message.

Pass printf formatted arguments. No trailing newline is needed.

Parameters
formatprintf-style format string. Arguments follow.

◆ log_err()

void void log_err ( const char *  format,
  ... 
)

Log error message.

Pass printf formatted arguments. No trailing newline is needed.

Parameters
formatprintf-style format string. Arguments follow.

◆ log_warn()

void void void log_warn ( const char *  format,
  ... 
)

Log warning message.

Pass printf formatted arguments. No trailing newline is needed.

Parameters
formatprintf-style format string. Arguments follow.

◆ log_hex()

void void void void log_hex ( const char *  msg,
void *  data,
size_t  length 
)

Log a hex-string to the log.

Can be any length. performs mallocs to do so, slow. But debug useful.

Parameters
msgstring desc to accompany the hexdump.
datadata to dump in hex format.
lengthlength of data.

References log_hex_f(), and verbosity.

Referenced by auth_zone_generate_zonemd_check(), and test_buffers().

◆ log_query()

void log_query ( const char *  format,
  ... 
)

Log query.

Pass printf formatted arguments. No trailing newline is needed.

Parameters
formatprintf-style format string. Arguments follow.

◆ log_reply()

void void log_reply ( const char *  format,
  ... 
)

Log reply.

Pass printf formatted arguments. No trailing newline is needed.

Parameters
formatprintf-style format string. Arguments follow.

◆ log_buf()

void void void log_buf ( enum verbosity_value  level,
const char *  msg,
struct sldns_buffer buf 
)

Easy alternative for log_hex, takes a sldns_buffer.

Parameters
levelverbosity level for this message, compared to global verbosity setting.
msgstring desc to print
bufthe buffer.

References log_hex_f(), sldns_buffer_begin(), sldns_buffer_limit(), and verbosity.

Referenced by test_buffers().

◆ fatal_exit()

void fatal_exit ( const char *  format,
  ... 
)

Log fatal error message, and exit the current process.

Pass printf formatted arguments. No trailing newline is needed.

Parameters
formatprintf-style format string. Arguments follow.

◆ log_vmsg()

void log_vmsg ( int  pri,
const char *  type,
const char *  format,
va_list  args 
)

va_list argument version of log_info.

Parameters
pripriority type, for example 5 (INFO).
typestring to designate type of message (info, error).
formatthe printf style format to print. no newline.
argsarguments for format string.

References logkey.

Referenced by fatal_exit(), log_err(), log_info(), log_warn(), and verbose().