tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

log_sys.c (1530B)


      1 /* Copyright (c) 2018-2021, The Tor Project, Inc. */
      2 /* See LICENSE for licensing information */
      3 
      4 /**
      5 * \file log_sys.c
      6 * \brief Setup and tear down the logging module.
      7 **/
      8 
      9 #include "orconfig.h"
     10 #include "lib/subsys/subsys.h"
     11 #include "lib/log/escape.h"
     12 #include "lib/log/log.h"
     13 #include "lib/log/log_sys.h"
     14 #include "lib/log/util_bug.h"
     15 #include "lib/metrics/metrics_store.h"
     16 
     17 static metrics_store_t *the_store;
     18 
     19 static int
     20 subsys_logging_initialize(void)
     21 {
     22  init_logging(0);
     23  the_store = metrics_store_new();
     24  return 0;
     25 }
     26 
     27 static void
     28 subsys_logging_shutdown(void)
     29 {
     30  logs_free_all();
     31  escaped(NULL);
     32 }
     33 
     34 static const smartlist_t *
     35 logging_metrics_get_stores(void)
     36 {
     37  static smartlist_t *stores_list = NULL;
     38 
     39  metrics_store_reset(the_store);
     40 
     41  metrics_store_entry_t *sentry = metrics_store_add(
     42      the_store,
     43      METRICS_TYPE_COUNTER,
     44      METRICS_NAME(bug_reached_count),
     45      "Total number of BUG() and similar assertion reached",
     46      0, NULL);
     47  metrics_store_entry_update(sentry, tor_bug_get_count());
     48 
     49  if (!stores_list) {
     50    stores_list = smartlist_new();
     51    smartlist_add(stores_list, the_store);
     52  }
     53 
     54  return stores_list;
     55 }
     56 
     57 const subsys_fns_t sys_logging = {
     58  .name = "log",
     59  SUBSYS_DECLARE_LOCATION(),
     60  .supported = true,
     61  /* Logging depends on threads, approx time, raw logging, and security.
     62   * Most other lib modules depend on logging. */
     63  .level = -90,
     64  .initialize = subsys_logging_initialize,
     65  .shutdown = subsys_logging_shutdown,
     66  .get_metrics = logging_metrics_get_stores,
     67 };