unbound: util/log.c File Reference

unbound 0.1

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>`
`#include <sys/time.h>`

## Macros
#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

## Functions
void | log_init (const char *filename, int use_syslog, const char *chrootdir)
| call this to initialize logging services.
void | log_file (FILE *f)
| Set logging to go to the specified file *.
void | log_thread_set (int *num)
| Init a thread (will print this number for the thread log entries).
int | log_thread_get (void)
| Get the thread id from logging system.
void | log_ident_set (const char *id)
| Set identity to print, default is 'unbound'.
void | log_ident_set_default (const char *id)
| Set default identity to print, default is 'unbound'.
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.
void | log_set_time_asc (int use_asc)
| Set if the time value is printed ascii or decimal in log entries.
void | log_set_time_iso (int use_iso)
| Set if the time value is printed in ISO8601 format.
void * | log_get_lock (void)
| get log lock
void | log_vmsg (int pri, const char *type, const char *format, va_list args)
| va_list argument version of log_info.
void | log_info (const char *format,...)
| implementation of log_info
void | log_err (const char *format,...)
| implementation of log_err
void | log_warn (const char *format,...)
| implementation of log_warn
void | fatal_exit (const char *format,...)
| implementation of fatal_exit
void | verbose (enum verbosity_value level, const char *format,...)
| implementation of verbose
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.
void | log_query (const char *format,...)
void | log_reply (const char *format,...)
void | log_buf (enum verbosity_value level, const char *msg, sldns_buffer *buf)
| Easy alternative for log_hex, takes a sldns_buffer.

## Variables
enum verbosity_value | verbosity = NO_VERBOSE
| The global verbosity setting.
static FILE * | logfile = 0
| the file logged to.
static int | key_created = 0
| if key has been created
static ub_thread_key_type | logkey
| pthread key for thread ids in logfile
static lock_basic_type | log_lock
| pthread mutex to protect FILE*
static const char * | ident ="unbound"
| the identity of this executable/process
static const char * | default_ident ="unbound"
static int | log_time_asc = 0
| print time in UTC or in secondsfrom1970
static int | log_time_iso = 0
| print time in iso format

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

Parameters

  filename | if NULL stderr is used.
  use_syslog | set to true to ignore filename and use syslog(3).
  chrootdir | to 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(), main(), main(), perform_setup(), run_daemon(), service_init(), service_start(), ub_ctx_create_nopipe(), and verbose().

## ◆ 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

  f | to that file, or pass NULL to disable logging.

References log_lock, and logfile.

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

## ◆ 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

  num | number to print for this thread. Owned by caller, must continue to exist.

References logkey.

Referenced by daemon_cleanup(), dnstap_io(), ext_thread(), fast_reload_thread_main(), libworker_dobg(), set_log_thread_id(), test_thr_main(), test_thr_main(), verbose(), and win_do_cron().

## ◆ 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.

Referenced by log_vmsg(), and verbose().

## ◆ log_ident_set()

void log_ident_set | ( | const char * | id | ) |

Set identity to print, default is 'unbound'.

Parameters

  id | string to print. Name of executable.

References ident.

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

## ◆ log_ident_set_default()

void log_ident_set_default | ( | const char * | id | ) |

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

Parameters

  id | string to print. Name of executable.

Referenced by main(), and verbose().

## ◆ 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

  identity | the identity to set.

References log_ident_set().

Referenced by apply_settings(), fr_reload_config(), and verbose().

## ◆ 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_asc | if 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(), config_set_option(), and verbose().

## ◆ log_set_time_iso()

void log_set_time_iso | ( | int | use_iso | ) |

Set if the time value is printed in ISO8601 format.

Parameters

  use_iso | if true, ascii timestamps are formatted in iso format.

References log_time_iso.

Referenced by config_apply(), config_set_option(), and verbose().

## ◆ log_vmsg()

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

va_list argument version of log_info.

Parameters

  pri | priority type, for example 5 (INFO).
  type | string to designate type of message (info, error).
  format | the printf style format to print. no newline.
  args | arguments for format string.

References ident, log_lock, log_thread_get(), log_time_asc, log_time_iso, logfile, MSG_GENERIC_ERR, MSG_GENERIC_INFO, MSG_GENERIC_SUCCESS, MSG_GENERIC_WARN, and SERVICE_NAME.

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

## ◆ log_info()

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

implementation of log_info

Parameters

  format | format string printf-style.

References log_vmsg().

Referenced by alloc_stats(), answer_check_it(), apply_http(), auth_zone_generate_answer(), autotrust_check(), autr_debug_print_ta(), autr_debug_print_tp(), checkfile(), comm_point_drop_reply(), comm_point_send_reply(), comm_point_send_udp_msg(), comm_point_tcp_accept_callback(), comm_timer_disable(), comm_timer_set(), daemon_fork(), delegpt_log(), do_expire_message(), do_flush_message(), do_infra_rtt(), do_moment_and_advance(), dtio_mainfdcallback(), dtio_tap_callback(), expon_timeout_backoff(), fake_front_query(), invalidateQueryInCache(), local_zones_print(), log_dns_msg(), log_info(), log_nametypeclass(), log_packed_rrset(), log_pkt(), log_query_in(), log_reply_info(), log_testpkt_reply_pkt(), lruhash_status(), macro_print_debug(), main(), mesh_stats(), moment_assign(), outnet_serviced_query_stop(), packed_rr_to_string(), pending_find_match(), pending_tcp_query(), pending_udp_query(), processFinished(), receive_bytes(), regional_log_stats(), replay_scenario_read(), reply_with_accept(), reply_with_finish(), respip_merge_cname(), run_scenario(), server_stats_log(), pymod::setTTL(), pymod_thread::setTTL(), setup_and_run(), setup_playback(), sigdate_error(), slabhash_status(), tempfile_check(), test_buffers(), test_long_table(), testlookup(), testlookup(), testlookup_unlim(), testlookup_unlim(), time_passes(), timehist_log(), verbose_print_unbound_socket(), waitforubanchor(), and worker_mem_report().

## ◆ log_err()

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

implementation of log_err

Parameters

  format | format string printf-style.

References log_vmsg().

Referenced by accept_open(), acl_find_or_create(), acl_find_or_create_str2addr(), acl_interface_str_cfg(), 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_new_key(), anchor_store_str(), anchors_add_insecure(), anchors_apply_cfg(), anchors_assemble_rrsets(), answer_chaos(), apply_axfr(), apply_http(), auth_addr_list_copy(), auth_master_copy(), auth_master_new(), auth_xfer_create(), auth_zone_delegpt(), auth_zone_read_zonefile(), auth_zone_set_fallback(), auth_zone_set_zonefile(), auth_zone_verify_zonemd_with_key(), auth_zone_write_chunks(), auth_zone_write_file(), auth_zone_zonemd_fail(), auth_zones_apply_cfg(), auth_zones_cfg(), auth_zones_create(), auth_zones_find_or_add_zone(), auth_zones_pickup_zonemd_verify(), autotrust_check(), autr_process_prime(), autr_read_file(), autr_tp_create(), autr_write_file(), az_insert_rr(), az_insert_rr_decompress(), az_parse_file(), az_remove_rr(), az_remove_rr_decompress(), call_root_update(), caps_white_apply_cfg(), caps_white_create(), cfg_apply_local_port_policy(), cfg_mark_ports(), cfg_parse_local_zone(), cfg_parse_memsize(), cfg_ptr_reverse(), check_auth_name_for_ssl(), check_contains_revoked(), check_data(), check_order_lock(), check_zone_invariants(), checkconf(), checkconnecterr(), checkrlimits(), comm_base_delete(), comm_base_delete_no_base(), comm_base_exit(), comm_point_close(), comm_point_create_doq(), comm_point_create_http_out(), 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_http_handle_callback(), comm_point_listen_for_rw(), comm_point_local_handle_callback(), comm_point_perform_accept(), 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_tcp_handle_read(), comm_point_udp_callback(), comm_signal_bind(), comm_signal_create(), comm_timer_create(), comm_timer_set(), config_parse_taglist(), config_read(), connect_sslctx_create(), consume_pp2_header(), cookie_secret_file_read(), cookie_secrets_apply_cfg(), create_local_accept_sock(), create_socketpair(), create_tcp_accept_sock(), create_udp_sock(), createResponse(), ct_create_sslctxs(), daemon_delete(), daemon_init(), daemon_remote_create(), daemon_remote_exec(), daemon_remote_open_accept(), dname_pkt_copy(), dns64_apply_cfg(), dns64_inform_super(), dns64_init(), dns64_insert_ignore_aaaa(), dns64_operate(), dns_alloc_msg(), dns_cache_find_delegation(), dns_cache_store_msg(), dnsc_load_local_data(), dnskey_verify_rrset_sig(), dnstap_io(), do_macro_arith(), do_macro_ctime(), do_macro_range(), do_macro_variable(), do_moment_and_advance(), do_proxy(), domain_limit_findcreate(), donotq_str_cfg(), ds_response_to_ke(), dt_io_thread_apply_cfg(), dt_io_thread_start(), dt_io_thread_stop(), dt_msg_queue_submit(), dtio_add_output_event_read(), dtio_add_output_event_write(), dtio_check_nb_connect(), dtio_cmd_cb(), dtio_control_stop_flush(), dtio_open_output(), dtio_open_output_local(), dtio_open_output_tcp(), dtio_read_accept_frame(), dtio_reconnect_enable(), dtio_stop_flush_exit(), dtio_tap_callback(), dtio_wakeup(), dtio_write_buf(), dump_msg_entry(), dup_all(), dup_prefix(), dynlibmod_init(), edns_register_option(), edns_strings_apply_cfg(), errinf_to_str_bogus(), errinf_to_str_misc(), errinf_to_str_servfail(), error_supers(), fast_reload_thread_start(), fd_for_dest(), fd_set_block(), fd_set_nonblock(), fetch_fill(), fill_nsec3_iter(), find_add_tp(), find_covering_nsec3(), find_matching_nsec3(), forwards_insert_data(), fr_add_auth_zone_change(), fr_check_cmd_from_thread(), fr_client_send_item_fd(), fr_construct_from_config(), fr_finish_time(), fr_init_time(), fr_load_config(), fr_main_handle_cmd(), fr_main_perform_cmd(), fr_output_text(), fr_poll_for_ack(), fr_poll_for_quit(), fr_poll_for_reload_start(), fr_read_ack_from_workers(), fr_send_cmd_to(), fr_send_notification(), generate_keytag_query(), generate_ns_check(), generate_request(), generate_sub_request(), get_rr_nameclass(), handle_event_moddone(), handle_newq(), handle_req(), hdlr(), hints_insert(), http_parse_add_rr(), http_zonefile_syntax_check(), infra_set_lame(), inplace_cb_register(), ipset_init(), ipset_operate(), ipset_startup(), iter_apply_cfg(), iter_dns_store(), iter_init(), iter_lookup_parent_glue_from_cache(), iter_operate(), iter_store_parentside_neg(), iter_store_parentside_rrset(), key_cache_create(), libworker_do_cmd(), libworker_dobg(), libworker_enter_result(), listen_create(), listen_sslctx_create(), listen_sslctx_setup_ticket_keys(), listening_ports_open(), load_trustanchor(), local_alias_shallow_copy_qname(), local_zone_enter_defaults(), local_zone_enter_rr(), local_zones_add_zone(), log_crypto_err_code(), log_dns_msg(), log_err(), log_err_addr(), log_init(), log_py_err(), 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_auth_holes(), make_scenario(), make_sock(), make_sock_port(), make_stub_holes(), make_tcp_accept(), mesh_add_sub(), mesh_continue(), mesh_create(), mesh_new_client(), mesh_query_done(), mesh_serve_expired_callback(), mesh_state_attachment(), modstack_call_init(), modstack_call_startup(), modstack_config(), nat64_apply_cfg(), neg_insert_data(), netblockstrtoaddr(), new_cname_override(), new_local_rrset(), new_rrset(), next_state(), nsec3_calc_b32(), nsec3_calc_hash(), nsec3_ce_wildcard(), nsec3_get_hashed(), nth_rtt(), outnet_comm_point_for_http(), outnet_comm_point_for_tcp(), outnet_comm_point_for_udp(), outnet_tcp_take_into_use(), outside_network_create(), parse_acl_access(), parse_comments(), parse_delegpt(), parse_dname(), parse_edns_options_from_query(), parse_extract_edns_from_response_msg(), parse_url(), parse_var_line(), perform_setup(), perfreply(), perfselect(), perfsend(), pick_outgoing_tcp(), populate_action_info(), ports_create_if(), prealloc_blocks(), prealloc_setup(), prime_root(), prime_stub(), prime_supers(), prime_trust_anchor(), primeResponseToKE(), print_hist(), print_id(), probe_anchor(), process_answer_detail(), process_bind_contents(), process_dnskey_response(), process_ds_response(), process_response(), processClassResponse(), processDSNSResponse(), processFinished(), processFinished(), processInitRequest(), processInitRequest2(), processLastResort(), processQueryResponse(), processQueryTargets(), processTargetResponse(), processValidate(), 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(), receive_bytes(), receive_bytes(), remote_handshake_later(), replay_moment_read(), replay_range_read(), replay_scenario_read(), reply_info_answer_encode(), reply_with_accept(), reply_with_finish(), resolve_interface_names(), respip_action_cfg(), respip_enter_rr(), respip_find_or_create(), respip_operate(), respip_rewrite_reply(), respip_sockaddr_find_or_create(), respip_views_apply_cfg(), reuse_tcp_insert(), reuse_tcp_lru_touch(), reuse_tcp_remove_tree_list(), rpz_apply_cfg_elements(), rpz_insert_rr(), rpz_synthesize_cname_override_msg(), rrset_add_rr(), rrset_cache_update_wildcard(), rrset_canonical(), rrset_canonicalize_to_buffer(), rrset_create(), rrset_insert_rr(), rrset_moveover_rrsigs(), rrset_remove_rr(), rrstr_get_rr_content(), run_scenario(), scrub_normalize(), select_id(), select_ifport(), service(), service_init(), service_main(), service_send(), service_tcp_listen(), serviced_callbacks(), serviced_tcp_callback(), serviced_udp_callback(), set_auth_name_on_ssl(), set_recvpktinfo(), set_recvtimestamp(), pymod::setTTL(), pymod_thread::setTTL(), setup_comm_ssl(), signal_handling_record(), skip_to_special(), sock_list_insert(), sock_poll_timeout(), spool_txt_string(), ssl_cert_changed(), ssl_handle_read(), ssl_handle_write(), ssl_http_read_more(), ssl_http_write_more(), table_grow(), tap_socket_list_addevs(), tap_socket_new_local(), tap_socket_new_tcpaccept(), tap_socket_new_tlsaccept(), tap_socket_setup(), tcl_list_str_cfg(), tcp_relay_read(), tcp_relay_write(), tcp_req_info_add_result(), tcp_req_info_create(), tempfile_check(), tube_create(), tube_queue_item(), tube_read_msg(), tube_setup_bg_listen(), tube_setup_bg_write(), tube_write_msg(), ub_comm_base_now(), ub_ctx_create_nopipe(), ub_stop_bg(), ub_thr_fork_wait(), val_apply_cfg(), val_env_parse_key_iter(), val_inform_super(), val_init(), val_neg_addreferral(), val_neg_addreply(), val_neg_create(), val_operate(), validate_any_response(), validate_suspend_setup_timer(), views_apply_cfg(), views_enter_view_name(), wait_limit_netblock_findcreate(), waitforit(), waitforubanchor(), win_do_cron(), worker_create(), worker_handle_request(), worker_init(), worker_restart_timer(), worker_send_cmd(), worker_send_reload_ack(), worker_stop_and_wait(), write_out(), xfer_set_masters(), xfr_master_add_addrs(), xfr_probe_lookup_host(), xfr_probe_send_probe(), xfr_set_timeout(), xfr_transfer_init_fetch(), xfr_transfer_lookup_host(), xfr_write_after_update(), zonemd_lookup_dnskey(), and zonemd_offline_verify().

## ◆ log_warn()

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

implementation of log_warn

Parameters

  format | format string printf-style.

References log_vmsg().

Referenced by alloc_get_id(), anchors_assemble_rrsets(), apply_settings(), auth_zone_create(), auth_zone_zonemd_fail(), auth_zones_apply_cfg(), autr_read_file(), az_domain_create(), cfg_mark_ports(), check_holddown(), checkrlimits(), comm_point_tcp_accept_callback(), create_tcp_accept_sock(), create_udp_sock(), daemon_apply_cfg(), daemon_create_workers(), daemon_fork(), daemon_remote_create(), delegpt_add_rrset(), ds_response_to_ke(), dt_io_thread_apply_cfg(), go(), handle_origin(), iter_handle(), listen_create(), load_msg(), load_qinfo(), load_ref(), load_rr(), load_rrset(), local_rrset_remove_rr(), log_warn(), lz_enter_zone_dname(), main(), move_into_cache(), outnet_udp_cb(), perform_setup(), ports_create_if(), processQueryResponse(), read_fwds_host(), read_root_hints(), read_stubs_host(), respip_sockaddr_find_or_create(), ring_add(), rrset_array_unlock_touch(), rrset_insert_rr(), run_daemon(), service_init(), ub_thr_fork_wait(), val_handle(), val_init(), and views_enter_view_name().

## ◆ fatal_exit()

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

implementation of fatal_exit

Parameters

  format | format string printf-style.

References LOG_CRIT, and log_vmsg().

## ◆ verbose()

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

implementation of verbose

Parameters

  level | verbose level for the message.
  format | format string printf-style.

References log_vmsg(), VERB_DETAIL, 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.

Parameters

  msg | string desc to accompany the hexdump.
  data | data to dump in hex format.
  length | length of data.

References log_hex_f(), and verbosity.

Referenced by auth_zone_generate_zonemd_check(), log_warn(), and 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.

Parameters

  level | verbosity level for this message, compared to global verbosity setting.
  msg | string desc to print
  buf | the buffer.

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

Referenced by log_reply(), outnet_udp_cb(), serviced_callbacks(), and test_buffers().