From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:master commit in: files/misc/, roverlay/config/, roverlay/
Date: Tue, 25 Mar 2014 22:48:49 +0000 (UTC) [thread overview]
Message-ID: <1395786491.72102382e7f0c7e4bf1fd9b8aeabe28c64780e97.dywi@gentoo> (raw)
commit: 72102382e7f0c7e4bf1fd9b8aeabe28c64780e97
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Mar 25 22:28:11 2014 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Mar 25 22:28:11 2014 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=72102382
roverlay: --log-level, --verbose (-v) args
Sets the console log level.
---
files/misc/roverlay.bashcomp | 9 ++++++++-
roverlay/argparser.py | 35 +++++++++++++++++++++++++++++++++++
roverlay/argutil.py | 13 ++++++++++++-
roverlay/config/entrymap.py | 2 +-
roverlay/runtime.py | 14 ++++++++++++++
5 files changed, 70 insertions(+), 3 deletions(-)
diff --git a/files/misc/roverlay.bashcomp b/files/misc/roverlay.bashcomp
index c15dd96..e521c85 100644
--- a/files/misc/roverlay.bashcomp
+++ b/files/misc/roverlay.bashcomp
@@ -24,10 +24,11 @@ _roverlay_comp() {
'--ppr' '--print-package-rules'
'--help-config' '--list-config-entries' '--dump-file' '--strict'
'--stats' '--no-stats' '--dump-stats'
+ '--log-level' '--verbose'
)
local SHORTOPTS=(
- '-h' '-V' '-c' '-F' '-R' '-D' '-P' '-O' '-N' '-A' '-M'
+ '-h' '-V' '-c' '-F' '-R' '-D' '-P' '-O' '-N' '-A' '-M' '-v'
)
local CMDARGS=(
@@ -79,6 +80,12 @@ _roverlay_comp() {
true
;;
+ '--log-level')
+ COMPREPLY=(
+ $(compgen -W "DEBUG INFO WARN WARNING ERROR CRITICAL" -- "${cur}" )
+ )
+ ;;
+
*)
case "${cur}" in
--*)
diff --git a/roverlay/argparser.py b/roverlay/argparser.py
index 04feff8..2fa6ca1 100644
--- a/roverlay/argparser.py
+++ b/roverlay/argparser.py
@@ -14,6 +14,8 @@ import roverlay.util.objects
# lazy import
from roverlay.argutil import \
+ LOG_LEVELS, \
+ is_log_level, \
couldbe_fs_dir, couldbe_fs_file, couldbe_stdout_or_file, \
get_gid, is_gid, get_uid, is_uid, \
is_fs_dir, is_fs_dir_or_void, is_fs_file, \
@@ -34,6 +36,22 @@ class UsageAction ( argparse.Action ):
# --- end of UsageAction ---
+class VerbosityAction ( argparse.Action ):
+
+ def __init__ ( self, *args, **kwargs ):
+ super ( VerbosityAction, self ).__init__ ( *args, **kwargs )
+ self._log_levels = [ "DEBUG", "INFO" ]
+
+ def __call__ ( self, parser, namespace, values, option_string=None ):
+ setattr (
+ namespace, 'log_level_console',
+ ( self._log_levels.pop() if self._log_levels else "DEBUG" )
+ )
+ # --- end of __call__ (...) ---
+
+# --- end of VerbosityAction ---
+
+
class RoverlayArgumentParserBase ( roverlay.argutil.ArgumentParserProxy ):
DESCRIPTION_TEMPLATE = None
@@ -197,6 +215,12 @@ class RoverlayArgumentParserBase ( roverlay.argutil.ArgumentParserProxy ):
)
+ # misc, logging
+ if parsed.get ( 'log_level_console' ):
+ self.do_extraconf ( True, 'LOG.CONSOLE.enabled' )
+ self.do_extraconf ( parsed['log_level_console'], 'LOG.CONSOLE.level' )
+
+
if hasattr ( self.__class__, 'PARSE_TARGETS' ):
for attr in self.__class__.PARSE_TARGETS:
getattr ( self, 'parse_' + attr )()
@@ -523,6 +547,17 @@ class RoverlayArgumentParserBase ( roverlay.argutil.ArgumentParserProxy ):
help='print all stats to stdout at exit (raw format)',
)
+ arg (
+ '--log-level', dest='log_level_console', metavar='<log level>',
+ default=argparse.SUPPRESS,
+ flags=self.ARG_ADD_DEFAULT, type=is_log_level,
+ help='set console log level ({})'.format ( ', '.join ( LOG_LEVELS ) )
+ )
+
+ arg (
+ '-v', '--verbose', nargs=0, action=VerbosityAction,
+ help="increase verbosity (can be specified more than once)"
+ )
return arg
# --- end of setup_misc_minimal (...) ---
diff --git a/roverlay/argutil.py b/roverlay/argutil.py
index 093d7c9..2f6d34f 100644
--- a/roverlay/argutil.py
+++ b/roverlay/argutil.py
@@ -10,9 +10,20 @@ import pwd
import grp
import sys
-
+import roverlay.config.entrymap
from roverlay.config.entryutil import deref_entry_safe
+# ref
+LOG_LEVELS = roverlay.config.entrymap.LOG_LEVEL
+
+def is_log_level ( s ):
+ sup = s.upper()
+ if sup in LOG_LEVELS:
+ return sup
+
+ raise argparse.ArgumentTypeError ( "not a log level: {}".format ( s ) )
+# --- end of is_log_level (...) ---
+
def get_uid ( user ):
try:
return int ( user )
diff --git a/roverlay/config/entrymap.py b/roverlay/config/entrymap.py
index b53d5a6..fb285a1 100644
--- a/roverlay/config/entrymap.py
+++ b/roverlay/config/entrymap.py
@@ -634,7 +634,7 @@ CONFIG_ENTRY_MAP = dict (
)
del fs_file, fs_abslist, is_fs_file, is_yesno, is_log_level, \
- CAPSLOCK, LOG_LEVEL, only_vtype
+ CAPSLOCK, only_vtype
def prune_description():
"""Removes the description strings from all config entries."""
diff --git a/roverlay/runtime.py b/roverlay/runtime.py
index 26edd00..829940e 100644
--- a/roverlay/runtime.py
+++ b/roverlay/runtime.py
@@ -4,6 +4,7 @@
# Distributed under the terms of the GNU General Public License;
# either version 2 of the License, or (at your option) any later version.
+import functools
import logging
import errno
import os
@@ -122,6 +123,19 @@ class RuntimeEnvironmentBase ( MinimalRuntimeEnvironment ):
# --- end of do_setup_parser (...) ---
def do_setup_config ( self ):
+ # set console logging _before_ loading the config file so that
+ # ConfigTree (debug) messages are visible
+ #
+ console_log_level = functools.reduce (
+ ( lambda d, k: dict.get ( d, k ) if d else None ),
+ [ "LOG", "CONSOLE", "level" ],
+ self.additional_config
+ )
+
+ if console_log_level:
+ roverlay.recipe.easylogger.force_reset()
+ roverlay.recipe.easylogger.setup_initial ( log_level=console_log_level )
+
try:
self.config = roverlay.core.load_config_file (
self.options ['config_file'],
reply other threads:[~2014-03-25 22:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1395786491.72102382e7f0c7e4bf1fd9b8aeabe28c64780e97.dywi@gentoo \
--to=dywi@mailerd.de \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox