Tor 0.4.9.0-alpha-dev
log_sys.c
Go to the documentation of this file.
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"
16
18
19static int
20subsys_logging_initialize(void)
21{
22 init_logging(0);
24 return 0;
25}
26
27static void
28subsys_logging_shutdown(void)
29{
31 escaped(NULL);
32}
33
34static const smartlist_t *
35logging_metrics_get_stores(void)
36{
37 static smartlist_t *stores_list = NULL;
38
40
41 metrics_store_entry_t *sentry = metrics_store_add(
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
57const subsys_fns_t sys_logging = {
58 .name = "log",
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};
const char * escaped(const char *s)
Definition: escape.c:126
Header for escape.c.
void init_logging(int disable_startup_queue)
Definition: log.c:916
void logs_free_all(void)
Definition: log.c:750
Headers for log.c.
Declare subsystem object for the logging module.
metrics_store_t * metrics_store_new(void)
Definition: metrics_store.c:74
metrics_store_entry_t * metrics_store_add(metrics_store_t *store, metrics_type_t type, const char *name, const char *help, size_t bucket_count, const int64_t *buckets)
void metrics_store_reset(metrics_store_t *store)
Header for lib/metrics/metrics_store.c.
void metrics_store_entry_update(metrics_store_entry_t *entry, const int64_t value)
static metrics_store_t * the_store
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
const char * name
Definition: subsys.h:43
Types used to declare a subsystem.
#define SUBSYS_DECLARE_LOCATION()
Definition: subsys.h:211
Macros to manage assertions, fatal and non-fatal.