1 |
commit: 72102382e7f0c7e4bf1fd9b8aeabe28c64780e97 |
2 |
Author: André Erdmann <dywi <AT> mailerd <DOT> de> |
3 |
AuthorDate: Tue Mar 25 22:28:11 2014 +0000 |
4 |
Commit: André Erdmann <dywi <AT> mailerd <DOT> de> |
5 |
CommitDate: Tue Mar 25 22:28:11 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=72102382 |
7 |
|
8 |
roverlay: --log-level, --verbose (-v) args |
9 |
|
10 |
Sets the console log level. |
11 |
|
12 |
--- |
13 |
files/misc/roverlay.bashcomp | 9 ++++++++- |
14 |
roverlay/argparser.py | 35 +++++++++++++++++++++++++++++++++++ |
15 |
roverlay/argutil.py | 13 ++++++++++++- |
16 |
roverlay/config/entrymap.py | 2 +- |
17 |
roverlay/runtime.py | 14 ++++++++++++++ |
18 |
5 files changed, 70 insertions(+), 3 deletions(-) |
19 |
|
20 |
diff --git a/files/misc/roverlay.bashcomp b/files/misc/roverlay.bashcomp |
21 |
index c15dd96..e521c85 100644 |
22 |
--- a/files/misc/roverlay.bashcomp |
23 |
+++ b/files/misc/roverlay.bashcomp |
24 |
@@ -24,10 +24,11 @@ _roverlay_comp() { |
25 |
'--ppr' '--print-package-rules' |
26 |
'--help-config' '--list-config-entries' '--dump-file' '--strict' |
27 |
'--stats' '--no-stats' '--dump-stats' |
28 |
+ '--log-level' '--verbose' |
29 |
) |
30 |
|
31 |
local SHORTOPTS=( |
32 |
- '-h' '-V' '-c' '-F' '-R' '-D' '-P' '-O' '-N' '-A' '-M' |
33 |
+ '-h' '-V' '-c' '-F' '-R' '-D' '-P' '-O' '-N' '-A' '-M' '-v' |
34 |
) |
35 |
|
36 |
local CMDARGS=( |
37 |
@@ -79,6 +80,12 @@ _roverlay_comp() { |
38 |
true |
39 |
;; |
40 |
|
41 |
+ '--log-level') |
42 |
+ COMPREPLY=( |
43 |
+ $(compgen -W "DEBUG INFO WARN WARNING ERROR CRITICAL" -- "${cur}" ) |
44 |
+ ) |
45 |
+ ;; |
46 |
+ |
47 |
*) |
48 |
case "${cur}" in |
49 |
--*) |
50 |
|
51 |
diff --git a/roverlay/argparser.py b/roverlay/argparser.py |
52 |
index 04feff8..2fa6ca1 100644 |
53 |
--- a/roverlay/argparser.py |
54 |
+++ b/roverlay/argparser.py |
55 |
@@ -14,6 +14,8 @@ import roverlay.util.objects |
56 |
|
57 |
# lazy import |
58 |
from roverlay.argutil import \ |
59 |
+ LOG_LEVELS, \ |
60 |
+ is_log_level, \ |
61 |
couldbe_fs_dir, couldbe_fs_file, couldbe_stdout_or_file, \ |
62 |
get_gid, is_gid, get_uid, is_uid, \ |
63 |
is_fs_dir, is_fs_dir_or_void, is_fs_file, \ |
64 |
@@ -34,6 +36,22 @@ class UsageAction ( argparse.Action ): |
65 |
# --- end of UsageAction --- |
66 |
|
67 |
|
68 |
+class VerbosityAction ( argparse.Action ): |
69 |
+ |
70 |
+ def __init__ ( self, *args, **kwargs ): |
71 |
+ super ( VerbosityAction, self ).__init__ ( *args, **kwargs ) |
72 |
+ self._log_levels = [ "DEBUG", "INFO" ] |
73 |
+ |
74 |
+ def __call__ ( self, parser, namespace, values, option_string=None ): |
75 |
+ setattr ( |
76 |
+ namespace, 'log_level_console', |
77 |
+ ( self._log_levels.pop() if self._log_levels else "DEBUG" ) |
78 |
+ ) |
79 |
+ # --- end of __call__ (...) --- |
80 |
+ |
81 |
+# --- end of VerbosityAction --- |
82 |
+ |
83 |
+ |
84 |
class RoverlayArgumentParserBase ( roverlay.argutil.ArgumentParserProxy ): |
85 |
|
86 |
DESCRIPTION_TEMPLATE = None |
87 |
@@ -197,6 +215,12 @@ class RoverlayArgumentParserBase ( roverlay.argutil.ArgumentParserProxy ): |
88 |
) |
89 |
|
90 |
|
91 |
+ # misc, logging |
92 |
+ if parsed.get ( 'log_level_console' ): |
93 |
+ self.do_extraconf ( True, 'LOG.CONSOLE.enabled' ) |
94 |
+ self.do_extraconf ( parsed['log_level_console'], 'LOG.CONSOLE.level' ) |
95 |
+ |
96 |
+ |
97 |
if hasattr ( self.__class__, 'PARSE_TARGETS' ): |
98 |
for attr in self.__class__.PARSE_TARGETS: |
99 |
getattr ( self, 'parse_' + attr )() |
100 |
@@ -523,6 +547,17 @@ class RoverlayArgumentParserBase ( roverlay.argutil.ArgumentParserProxy ): |
101 |
help='print all stats to stdout at exit (raw format)', |
102 |
) |
103 |
|
104 |
+ arg ( |
105 |
+ '--log-level', dest='log_level_console', metavar='<log level>', |
106 |
+ default=argparse.SUPPRESS, |
107 |
+ flags=self.ARG_ADD_DEFAULT, type=is_log_level, |
108 |
+ help='set console log level ({})'.format ( ', '.join ( LOG_LEVELS ) ) |
109 |
+ ) |
110 |
+ |
111 |
+ arg ( |
112 |
+ '-v', '--verbose', nargs=0, action=VerbosityAction, |
113 |
+ help="increase verbosity (can be specified more than once)" |
114 |
+ ) |
115 |
|
116 |
return arg |
117 |
# --- end of setup_misc_minimal (...) --- |
118 |
|
119 |
diff --git a/roverlay/argutil.py b/roverlay/argutil.py |
120 |
index 093d7c9..2f6d34f 100644 |
121 |
--- a/roverlay/argutil.py |
122 |
+++ b/roverlay/argutil.py |
123 |
@@ -10,9 +10,20 @@ import pwd |
124 |
import grp |
125 |
import sys |
126 |
|
127 |
- |
128 |
+import roverlay.config.entrymap |
129 |
from roverlay.config.entryutil import deref_entry_safe |
130 |
|
131 |
+# ref |
132 |
+LOG_LEVELS = roverlay.config.entrymap.LOG_LEVEL |
133 |
+ |
134 |
+def is_log_level ( s ): |
135 |
+ sup = s.upper() |
136 |
+ if sup in LOG_LEVELS: |
137 |
+ return sup |
138 |
+ |
139 |
+ raise argparse.ArgumentTypeError ( "not a log level: {}".format ( s ) ) |
140 |
+# --- end of is_log_level (...) --- |
141 |
+ |
142 |
def get_uid ( user ): |
143 |
try: |
144 |
return int ( user ) |
145 |
|
146 |
diff --git a/roverlay/config/entrymap.py b/roverlay/config/entrymap.py |
147 |
index b53d5a6..fb285a1 100644 |
148 |
--- a/roverlay/config/entrymap.py |
149 |
+++ b/roverlay/config/entrymap.py |
150 |
@@ -634,7 +634,7 @@ CONFIG_ENTRY_MAP = dict ( |
151 |
) |
152 |
|
153 |
del fs_file, fs_abslist, is_fs_file, is_yesno, is_log_level, \ |
154 |
- CAPSLOCK, LOG_LEVEL, only_vtype |
155 |
+ CAPSLOCK, only_vtype |
156 |
|
157 |
def prune_description(): |
158 |
"""Removes the description strings from all config entries.""" |
159 |
|
160 |
diff --git a/roverlay/runtime.py b/roverlay/runtime.py |
161 |
index 26edd00..829940e 100644 |
162 |
--- a/roverlay/runtime.py |
163 |
+++ b/roverlay/runtime.py |
164 |
@@ -4,6 +4,7 @@ |
165 |
# Distributed under the terms of the GNU General Public License; |
166 |
# either version 2 of the License, or (at your option) any later version. |
167 |
|
168 |
+import functools |
169 |
import logging |
170 |
import errno |
171 |
import os |
172 |
@@ -122,6 +123,19 @@ class RuntimeEnvironmentBase ( MinimalRuntimeEnvironment ): |
173 |
# --- end of do_setup_parser (...) --- |
174 |
|
175 |
def do_setup_config ( self ): |
176 |
+ # set console logging _before_ loading the config file so that |
177 |
+ # ConfigTree (debug) messages are visible |
178 |
+ # |
179 |
+ console_log_level = functools.reduce ( |
180 |
+ ( lambda d, k: dict.get ( d, k ) if d else None ), |
181 |
+ [ "LOG", "CONSOLE", "level" ], |
182 |
+ self.additional_config |
183 |
+ ) |
184 |
+ |
185 |
+ if console_log_level: |
186 |
+ roverlay.recipe.easylogger.force_reset() |
187 |
+ roverlay.recipe.easylogger.setup_initial ( log_level=console_log_level ) |
188 |
+ |
189 |
try: |
190 |
self.config = roverlay.core.load_config_file ( |
191 |
self.options ['config_file'], |