Macros | Functions | Variables
log.c File Reference

Implementation of log.h. More...

#include "config.h"
#include "util/log.h"
#include "util/locks.h"
#include "sldns/sbuffer.h"
#include <stdarg.h>


#define LOG_CRIT   2
 define LOG_ constants
#define LOG_ERR   3
#define LOG_WARNING   4
#define LOG_NOTICE   5
#define LOG_INFO   6
#define LOG_DEBUG   7


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_set_time (time_t *t)
 Set the time value to print in log entries. 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_vmsg (int pri, const char *type, const char *format, va_list args)
 va_list argument version of log_info. More...
void log_info (const char *format,...)
 implementation of log_info More...
void log_err (const char *format,...)
 implementation of log_err More...
void log_warn (const char *format,...)
 implementation of log_warn More...
void fatal_exit (const char *format,...)
 implementation of fatal_exit More...
void verbose (enum verbosity_value level, const char *format,...)
 implementation of verbose More...
static void log_hex_f (enum verbosity_value v, const char *msg, void *data, size_t length)
 log hex data
void log_hex (const char *msg, void *data, size_t length)
 Log a hex-string to the log. More...
void log_buf (enum verbosity_value level, const char *msg, sldns_buffer *buf)
 Easy alternative for log_hex, takes a sldns_buffer. More...


enum verbosity_value verbosity = 0
 The global verbosity setting.
static FILE * logfile = 0
 the file logged to. More...
static int key_created = 0
 if key has been created
static ub_thread_key_t logkey
 pthread key for thread ids in logfile
static lock_quick_t log_lock
 pthread mutex to protect FILE*
static const char * ident ="unbound"
 the identity of this executable/process
static time_t * log_now = NULL
 time to print in log, if NULL, use time(2)
static int log_time_asc = 0
 print time in UTC or in secondsfrom1970

Detailed Description

Implementation of log.h.

Function Documentation

§ log_init()

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

call this to initialize logging services.

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.

fto that file, or pass NULL to disable logging.

References log_lock, and logfile.

Referenced by context_finalize(), and ub_ctx_debugout().

§ 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.

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

References logkey.

Referenced by daemon_cleanup(), 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.

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

References key_created, and logkey.

Referenced by outgoing_ssl_fd().

§ log_ident_set()

void log_ident_set ( const char *  id)

Set identity to print, default is 'unbound'.

idstring to print. Name of executable.

References ub_packed_rrset_key::id, and ident.

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

§ log_set_time()

void log_set_time ( time_t *  t)

Set the time value to print in log entries.

tthe point is copied and used to find the time. if NULL, time(2) is used.

References log_now.

Referenced by worker_delete().

§ 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.

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_vmsg()

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

va_list argument version of log_info.

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 ident, log_lock, log_now, log_time_asc, logfile, logkey, MSG_GENERIC_ERR, MSG_GENERIC_INFO, MSG_GENERIC_SUCCESS, MSG_GENERIC_WARN, and SERVICE_NAME.

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

§ log_info()

void log_info ( const char *  format,

§ log_err()

void log_err ( const char *  format,

implementation of log_err

formatformat string printf-style.

References log_vmsg().

Referenced by accept_open(), acl_find_or_create(), acl_list_str_cfg(), acl_list_tag_action_cfg(), acl_list_tag_data_cfg(), acl_list_tags_cfg(), acl_list_view_cfg(), add_bg_result(), add_open(), add_trustanchor_frm_str(), ah(), alloc_special_obtain(), anchor_insert_insecure(), anchor_read_bind_file(), anchor_read_bind_file_wild(), anchor_read_file(), anchor_store_str(), anchors_add_insecure(), anchors_apply_cfg(), anchors_assemble_rrsets(), answer_chaos(), apply_settings(), autr_read_file(), autr_tp_create(), autr_write_file(), call_root_update(), caps_white_apply_cfg(), cfg_mark_ports(), cfg_parse_local_zone(), cfg_parse_memsize(), cfg_ptr_reverse(), check_data(), check_order_lock(), check_zone_invariants(), comm_base_delete(), comm_base_delete_no_base(), comm_base_exit(), comm_point_close(), comm_point_create_local(), comm_point_create_raw(), comm_point_create_tcp(), comm_point_create_tcp_handler(), comm_point_create_tcp_out(), comm_point_create_udp(), comm_point_create_udp_ancil(), comm_point_listen_for_rw(), comm_point_local_handle_callback(), comm_point_send_udp_msg(), comm_point_send_udp_msg_if(), comm_point_start_listening(), comm_point_stop_listening(), comm_point_tcp_handle_callback(), comm_point_udp_ancil_callback(), comm_point_udp_callback(), comm_signal_bind(), comm_signal_create(), comm_timer_create(), comm_timer_set(), config_parse_taglist(), config_read(), connect_sslctx_create(), create_local_accept_sock(), create_tcp_accept_sock(), create_udp_sock(), createResponse(), daemon_delete(), daemon_remote_create(), daemon_remote_exec(), daemon_remote_open_accept(), dname_pkt_copy(), dns64_apply_cfg(), dns64_init(), dns_alloc_msg(), dns_cache_find_delegation(), dns_cache_store_msg(), do_macro_arith(), do_macro_ctime(), do_macro_range(), do_macro_variable(), do_moment_and_advance(), do_proxy(), domain_limit_findcreate(), donotq_str_cfg(), edns_register_option(), errinf(), errinf_to_str(), error_supers(), fd_set_block(), fd_set_nonblock(), fill_nsec3_iter(), find_add_tp(), find_covering_nsec3(), find_matching_nsec3(), forwards_insert_data(), generate_ns_check(), generate_sub_request(), get_rr_content(), get_rr_nameclass(), handle_newq(), hdlr(), hints_insert(), infra_set_lame(), inplace_cb_query_register(), iter_apply_cfg(), iter_dns_store(), iter_init(), iter_lookup_parent_glue_from_cache(), iter_store_parentside_neg(), iter_store_parentside_rrset(), key_cache_create(), libworker_do_cmd(), libworker_dobg(), listen_create(), listen_sslctx_create(), load_trustanchor(), local_zones_add_zone(), log_crypto_err(), log_err_addr(), log_init(), lz_enter_defaults(), lz_enter_override(), lz_enter_rr_into_zone(), lz_enter_rr_str(), lz_enter_zone(), lz_enter_zone_dname(), lz_enter_zone_tag(), lz_exists(), lz_find_create_node(), lz_setup_implicit(), make_scenario(), make_sock(), make_sock_port(), make_stub_holes(), mesh_attach_sub(), mesh_continue(), mesh_create(), mesh_new_client(), mesh_new_prefetch(), mesh_state_attachment(), modstack_config(), modstack_setup(), neg_insert_data(), netblockstrtoaddr(), new_local_rrset(), next_state(), nsec3_calc_b32(), nsec3_calc_hash(), nsec3_ce_wildcard(), nsec3_get_hashed(), outside_network_create(), parse_comments(), parse_dname(), parse_var_line(), perfreply(), perfsend(), pick_outgoing_tcp(), prealloc_blocks(), prealloc_setup(), prime_root(), prime_stub(), print_hist(), print_id(), probe_anchor(), process_answer_detail(), process_bind_contents(), process_ds_response(), process_response(), processDLVLookup(), processFinished(), processInitRequest2(), pythonmod_deinit(), pythonmod_inform_super(), pythonmod_init(), read_addrs(), read_fetch_policy(), read_fwds_addr(), read_fwds_host(), read_fwds_name(), read_multiline(), read_names(), read_root_hints(), read_stubs_addr(), read_stubs_host(), read_stubs_name(), replay_moment_read(), replay_range_read(), rrset_canonical(), serviced_tcp_initiate(), serviced_udp_callback(), set_recvpktinfo(), signal_handling_record(), skip_to_special(), sock_list_insert(), ssl_handle_read(), ssl_handle_write(), table_grow(), tcp_callback_reader(), tcp_relay_read(), tcp_relay_write(), tube_create(), tube_queue_item(), tube_read_msg(), tube_write_msg(), ub_comm_base_now(), ub_ctx_create_nopipe(), ub_stop_bg(), ub_thr_fork_wait(), val_apply_cfg(), val_dlv_init(), val_init(), val_neg_addreferral(), val_neg_addreply(), val_neg_create(), val_operate(), validate_any_response(), views_apply_cfg(), views_enter_view_name(), waitforit(), waitforubanchor(), worker_create(), and worker_send_cmd().

§ log_warn()

void log_warn ( const char *  format,

§ fatal_exit()

void fatal_exit ( const char *  format,

implementation of fatal_exit

formatformat string printf-style.

References LOG_CRIT, and log_vmsg().

§ verbose()

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

implementation of verbose

levelverbose level for the message.
formatformat string printf-style.

References log_vmsg(), VERB_OPS, and verbosity.

Referenced by log_hex_f(), and log_init().

§ log_hex()

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.

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

References log_hex_f(), and verbosity.

Referenced by test_buffers().

§ log_buf()

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

Easy alternative for log_hex, takes a sldns_buffer.

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().

Variable Documentation

§ logfile

FILE* logfile = 0

the file logged to.

Referenced by config_get_option(), log_file(), log_init(), and log_vmsg().