libdlog: isolate limiter creation 95/185795/3
authorMichal Bloch <m.bloch@samsung.com>
Wed, 1 Aug 2018 17:17:50 +0000 (19:17 +0200)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 21 Aug 2018 02:49:38 +0000 (02:49 +0000)
Limiter no longer checks whether it is enabled on construction,
it is now the caller's responsibility. This allows to construct
limiter with a limited config (for example containing just the
ruleset) and possibly to add extra rules between deciding to use
the limiter and actually creating it (so that the extras needn't
be loaded if opting out of the feature).

Change-Id: I8e6a4ad06c782f17e47cd5e90a73a150cf327eb3
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
include/loglimiter.h
src/libdlog/log.c
src/libdlog/loglimiter.c

index 056fd09..eac9c7f 100644 (file)
@@ -32,7 +32,7 @@ void __log_limiter_destroy(void);
 
 int __log_limiter_pass_log(const char* tag, int prio);
 
-int __configure_limiter(struct log_config *config, int default_limiter);
+int __log_limiter_create(struct log_config *config);
 
 #ifdef __cplusplus
 }
index 678a877..c09e5a3 100644 (file)
@@ -67,6 +67,16 @@ static int __write_to_log_null(log_id_t log_id, log_priority prio, const char *t
        return DLOG_ERROR_NOT_PERMITTED; // LCOV_EXCL_LINE
 }
 
+static void __configure_limiter(struct log_config *config)
+{
+       assert(config);
+
+       if (!limiter)
+               return;
+
+       limiter = __log_limiter_create(config);
+}
+
 static int __configure_backend(struct log_config *config)
 {
        assert(config);
@@ -92,7 +102,7 @@ static void __configure_parameters(struct log_config *config)
        plog = log_config_get_int(config, "plog", DEFAULT_CONFIG_PLOG);
        debugmode = log_config_get_int(config, "debugmode", DEFAULT_CONFIG_DEBUGMODE);
        fatal_assert = access(DEBUGMODE_FILE, F_OK) != -1;
-       limiter = __configure_limiter(config, DEFAULT_CONFIG_LIMITER);
+       limiter = log_config_get_int(config, "limiter", DEFAULT_CONFIG_LIMITER);
 }
 
 /**
@@ -111,6 +121,8 @@ static void __configure(void)
        if (!__configure_backend(&config))
                goto failure;
 
+       __configure_limiter(&config);
+
        log_config_free(&config);
        return;
 
index af0f8dc..feff53f 100644 (file)
@@ -423,14 +423,10 @@ static void __config_iteration(const char* key, const char* value, void *u)
 }
 // LCOV_EXCL_STOP
 
-int __configure_limiter(struct log_config *config, int default_limiter)
+int __log_limiter_create(struct log_config *config)
 {
        assert(config);
 
-       int enabled = log_config_get_int(config, "limiter", default_limiter);
-       if (!enabled)
-               return 0;
-
        log_config_foreach(config, __config_iteration, NULL); // LCOV_EXCL_LINE
 
        return (__log_limiter_initialize() == 0); // LCOV_EXCL_LINE