|
From: Kouhei S. <nul...@cl...> - 2013-11-17 14:35:33
|
Kouhei Sutou 2013-11-17 23:26:06 +0900 (Sun, 17 Nov 2013) New Revision: fe0544f09895f3cce1e449991155e6b22724dd32 https://github.com/clear-code/cutter/commit/fe0544f09895f3cce1e449991155e6b22724dd32 Message: Add --log-level option Modified files: cutter/cut-main.c doc/cutter.rd doc/cutter.rd.ja test/cutter/test-cutter.c Modified: cutter/cut-main.c (+32 -1) =================================================================== --- cutter/cut-main.c 2013-11-17 21:57:29 +0900 (c4e0a5a) +++ cutter/cut-main.c 2013-11-17 23:26:06 +0900 (b090998) @@ -1,6 +1,6 @@ /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - * Copyright (C) 2007-2011 Kouhei Sutou <ko...@cl...> + * Copyright (C) 2007-2013 Kouhei Sutou <ko...@cl...> * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -45,6 +45,7 @@ char **environ = NULL; #include "cut-module-factory.h" #include "cut-contractor.h" #include "cut-utils.h" +#include "cut-logger.h" #include "../gcutter/gcut-main.h" #include "../gcutter/gcut-error.h" @@ -103,6 +104,31 @@ print_version (const gchar *option_name, const gchar *value, } static gboolean +parse_log_level (const gchar *option_name, + const gchar *value, + gpointer data, + GError **error) +{ + GError *log_level_error = NULL; + gboolean success; + + success = cut_logger_set_target_level_by_string(cut_logger(), + value, + &log_level_error); + if (!success) { + g_set_error(error, + G_OPTION_ERROR, + G_OPTION_ERROR_BAD_VALUE, + "%s: %s", + option_name, + log_level_error->message); + g_error_free(log_level_error); + } + + return success; +} + +static gboolean parse_mode (const gchar *option_name, const gchar *value, gpointer data, GError **error) { @@ -148,6 +174,11 @@ static const GOptionEntry option_entries[] = { {"version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, print_version, N_("Show version"), NULL}, + {"log-level", 0, 0, G_OPTION_ARG_CALLBACK, parse_log_level, + N_("Set log level to LEVEL. LEVEL can be combined them with '|': " + "(all|default|none|critical|error|warning|info|debug|trace) " + "(default: critical|error|warning)"), + "LEVEL"}, {"mode", 0, 0, G_OPTION_ARG_CALLBACK, parse_mode, N_("Set run mode (default: test)"), "[test|analyze|play]"}, {"source-directory", 's', 0, G_OPTION_ARG_STRING, &source_directory, Modified: doc/cutter.rd (+26 -0) =================================================================== --- doc/cutter.rd 2013-11-17 21:57:29 +0900 (5cfa1a7) +++ doc/cutter.rd 2013-11-17 23:26:06 +0900 (c1185f0) @@ -35,6 +35,32 @@ option is specified. Cutter shows its own version and exits. +: --log-level=LEVEL + + It sets log level to LEVEL. + + LEVEL can be combined them with '|' like "error|warning". + + You can add a level to the default level by prepending "+" to level + like "+trace|+info". + + You can remove a level from the default level by prepending "-" to level + like "-error|-warning". + + Here are available levels: + + * default: equals to "critical|error|warning". + * none: logs nothing. + * critical: logs only critial information. + * error: logs only error information. + * warning: logs only warning information. + * info: logs only additional information. + * debug: logs only debug information. + * traces: logs only trace information. + * all: logs all log information. + + The default is "default". + : --mode=[test|analyze] It specifies run mode. Cutter runs tests when run mode is Modified: doc/cutter.rd.ja (+26 -0) =================================================================== --- doc/cutter.rd.ja 2013-11-17 21:57:29 +0900 (e0810cc) +++ doc/cutter.rd.ja 2013-11-17 23:26:06 +0900 (001294b) @@ -36,6 +36,32 @@ Cutterはプログラマが新しいテストを書くこと、すでにある バージョンを表示して終了します。 +: --log-level=LEVEL + + ログレベルをLEVELに設定します。 + + LEVELは「error|warning」というように「|」で区切って指定できます。 + + 「+trace|+info」というようにレベルの前に「+」をつけるとデフォルトのレベルに + 指定したレベルを追加できます。 + + 「-error|-warning」というようにレベルの前に「-」をつけるとデフォルト + のレベルから指定したレベルを取り除けます。 + + 指定できるレベルは以下の通りです。 + + * default: 「critical|error|warning」と同じ。 + * none: なにも出力しない。 + * critical: 致命的な問題のみ出力。 + * error: エラーのみ出力。 + * warning: 警告のみ出力。 + * info: 付加情報のみ出力。 + * debug: デバッグ情報のみ出力。 + * traces: トレース情報のみ出力。 + * all: すべての情報を出力。 + + デフォルトは「default」です。 + : --mode=[test|analyze] 実行モードを指定します。testモードのときはテストを実行し Modified: test/cutter/test-cutter.c (+9 -1) =================================================================== --- test/cutter/test-cutter.c 2013-11-17 21:57:29 +0900 (d62206f) +++ test/cutter/test-cutter.c 2013-11-17 23:26:06 +0900 (99fbbdb) @@ -1,6 +1,6 @@ /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - * Copyright (C) 2008-2010 Kouhei Sutou <ko...@cl...> + * Copyright (C) 2008-2013 Kouhei Sutou <ko...@cl...> * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -103,6 +103,10 @@ cut_setup (void) "" LINE_FEED_CODE "Application Options:" LINE_FEED_CODE " --version Show version" LINE_FEED_CODE + " --log-level=LEVEL " + "Set log level to LEVEL. LEVEL can be combined them with '|': " + "(all|default|none|critical|error|warning|info|debug|trace) " + "(default: critical|error|warning)" LINE_FEED_CODE " --mode=[test|analyze|play] Set run mode (default: test)" LINE_FEED_CODE " -s, --source-directory=DIRECTORY Set directory of source code" LINE_FEED_CODE " -n, --name=TEST_NAME Specify tests" LINE_FEED_CODE @@ -281,6 +285,10 @@ test_help_all (void) #endif "Application Options:" LINE_FEED_CODE " --version Show version" LINE_FEED_CODE + " --log-level=LEVEL " + "Set log level to LEVEL. LEVEL can be combined them with '|': " + "(all|default|none|critical|error|warning|info|debug|trace) " + "(default: critical|error|warning)" LINE_FEED_CODE " --mode=[test|analyze|play] Set run mode (default: test)" LINE_FEED_CODE " -s, --source-directory=DIRECTORY Set directory of source code" LINE_FEED_CODE " -n, --name=TEST_NAME Specify tests" LINE_FEED_CODE |