summaryrefslogtreecommitdiff
path: root/src/lib/log
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-11-01 13:26:33 -0400
committerNick Mathewson <nickm@torproject.org>2018-11-05 09:22:02 -0500
commitd3e4afcc9b835e0f862207ef16d7e706ceea9ce1 (patch)
tree388168c197a1f428659a7ce136a7c5656f9b5f68 /src/lib/log
parentb8c50eabfee1bd9f5ed03f8ec569cc53b980f1d1 (diff)
downloadtor-d3e4afcc9b835e0f862207ef16d7e706ceea9ce1.tar.gz
tor-d3e4afcc9b835e0f862207ef16d7e706ceea9ce1.zip
Turn the logging code into a subsystem
Diffstat (limited to 'src/lib/log')
-rw-r--r--src/lib/log/.may_include1
-rw-r--r--src/lib/log/include.am2
-rw-r--r--src/lib/log/log.c1
-rw-r--r--src/lib/log/log_sys.c35
-rw-r--r--src/lib/log/log_sys.h14
5 files changed, 53 insertions, 0 deletions
diff --git a/src/lib/log/.may_include b/src/lib/log/.may_include
index 7ca1863a52..11c87f0a0d 100644
--- a/src/lib/log/.may_include
+++ b/src/lib/log/.may_include
@@ -9,6 +9,7 @@ lib/lock/*.h
lib/log/*.h
lib/malloc/*.h
lib/string/*.h
+lib/subsys/*.h
lib/testsupport/*.h
lib/version/*.h
lib/wallclock/*.h
diff --git a/src/lib/log/include.am b/src/lib/log/include.am
index c6f404e269..9d3dbe3104 100644
--- a/src/lib/log/include.am
+++ b/src/lib/log/include.am
@@ -9,6 +9,7 @@ src_lib_libtor_log_a_SOURCES = \
src/lib/log/escape.c \
src/lib/log/ratelim.c \
src/lib/log/log.c \
+ src/lib/log/log_sys.c \
src/lib/log/util_bug.c
if WIN32
@@ -24,5 +25,6 @@ noinst_HEADERS += \
src/lib/log/escape.h \
src/lib/log/ratelim.h \
src/lib/log/log.h \
+ src/lib/log/log_sys.h \
src/lib/log/util_bug.h \
src/lib/log/win32err.h
diff --git a/src/lib/log/log.c b/src/lib/log/log.c
index bc7b36dcb9..46107fe848 100644
--- a/src/lib/log/log.c
+++ b/src/lib/log/log.c
@@ -32,6 +32,7 @@
#define LOG_PRIVATE
#include "lib/log/log.h"
+#include "lib/log/log_sys.h"
#include "lib/version/git_revision.h"
#include "lib/log/ratelim.h"
#include "lib/lock/compat_mutex.h"
diff --git a/src/lib/log/log_sys.c b/src/lib/log/log_sys.c
new file mode 100644
index 0000000000..94ec97fdc1
--- /dev/null
+++ b/src/lib/log/log_sys.c
@@ -0,0 +1,35 @@
+/* Copyright (c) 2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file log_sys.c
+ * \brief Setup and tear down the logging module.
+ **/
+
+#include "orconfig.h"
+#include "lib/subsys/subsys.h"
+#include "lib/log/escape.h"
+#include "lib/log/log.h"
+#include "lib/log/log_sys.h"
+
+static int
+init_logging_subsys(void)
+{
+ init_logging(0);
+ return 0;
+}
+
+static void
+shutdown_logging_subsys(void)
+{
+ logs_free_all();
+ escaped(NULL);
+}
+
+const subsys_fns_t sys_logging = {
+ .name = "log",
+ .supported = true,
+ .level = -90,
+ .initialize = init_logging_subsys,
+ .shutdown = shutdown_logging_subsys,
+};
diff --git a/src/lib/log/log_sys.h b/src/lib/log/log_sys.h
new file mode 100644
index 0000000000..f7afbb279d
--- /dev/null
+++ b/src/lib/log/log_sys.h
@@ -0,0 +1,14 @@
+/* Copyright (c) 2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file log_sys.h
+ * \brief Declare subsystem object for the logging module.
+ **/
+
+#ifndef TOR_LOG_SYS_H
+#define TOR_LOG_SYS_H
+
+extern const struct subsys_fns_t sys_logging;
+
+#endif /* !defined(TOR_LOG_SYS_H) */