Navigation Menu

Skip to content

Commit

Permalink
Support changing default logger's max level before grn_init()
Browse files Browse the repository at this point in the history
grn_init() logs some messages such as vm.overcommit_memory related
messages. vm.overcommit_memory related messages uses INFO log level.
The messages never be logged because the default max log level is
NOTICE and the default max log level can't be changed before grn_init().
  • Loading branch information
kou committed Aug 20, 2012
1 parent 83c6906 commit 25b31d7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
3 changes: 3 additions & 0 deletions include/groonga.h
Expand Up @@ -2039,6 +2039,9 @@ GRN_API int grn_logger_pass(grn_ctx *ctx, grn_log_level level);
#define GRN_LOG_DEFAULT_LEVEL GRN_LOG_NOTICE
#endif /* GRN_LOG_DEFAULT_LEVEL */

GRN_API void grn_default_logger_set_max_level(grn_log_level level);
GRN_API grn_log_level grn_default_logger_get_max_level();

#define GRN_LOG(ctx,level,...) do {\
if (grn_logger_pass(ctx, level)) {\
grn_logger_put(ctx, (level), __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); \
Expand Down
12 changes: 12 additions & 0 deletions lib/ctx.c
Expand Up @@ -731,6 +731,18 @@ static grn_logger_info default_logger = {

static const grn_logger_info *grn_logger = &default_logger;

void
grn_default_logger_set_max_level(grn_log_level level)
{
default_logger.max_level = level;
}

grn_log_level
grn_default_logger_get_max_level(void)
{
return default_logger.max_level;
}

void
grn_log_reopen(grn_ctx *ctx)
{
Expand Down
27 changes: 14 additions & 13 deletions src/groonga.c
Expand Up @@ -2234,6 +2234,20 @@ main(int argc, char **argv)
grn_qlog_path = query_log_path_arg;
}

if (log_level_arg) {
const char * const end = log_level_arg + strlen(log_level_arg);
const char *rest = NULL;
const int value = grn_atoi(log_level_arg, end, &rest);
if (end != rest || value < 0 || value > 9) {
fprintf(stderr, "invalid log level: <%s>\n", log_level_arg);
return EXIT_FAILURE;
}
log_level = value;
} else {
log_level = default_log_level;
}
grn_default_logger_set_max_level(log_level);

if (max_num_threads_arg) {
const char * const end = max_num_threads_arg + strlen(max_num_threads_arg);
const char *rest = NULL;
Expand Down Expand Up @@ -2368,19 +2382,6 @@ main(int argc, char **argv)
default_match_escalation_threshold = default_default_match_escalation_threshold;
}

if (log_level_arg) {
const char * const end = log_level_arg + strlen(log_level_arg);
const char *rest = NULL;
const int value = grn_atoi(log_level_arg, end, &rest);
if (end != rest || value < 0 || value > 9) {
fprintf(stderr, "invalid log level: <%s>\n", log_level_arg);
return EXIT_FAILURE;
}
log_level = value;
} else {
log_level = default_log_level;
}

if (cache_limit_arg) {
const char * const end = cache_limit_arg + strlen(cache_limit_arg);
const char *rest = NULL;
Expand Down

0 comments on commit 25b31d7

Please sign in to comment.