Skip to content

Commit ac5fad6

Browse files
committed
Merge remote-tracking branch 'origin/30-set-log-level-cli'
2 parents 041a0cf + 88338e9 commit ac5fad6

File tree

6 files changed

+110
-79
lines changed

6 files changed

+110
-79
lines changed

Diff for: keg/cli.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from collections import defaultdict
44
from contextlib import contextmanager
5+
import logging
56

67
import click
78
import flask
@@ -258,18 +259,22 @@ def option_processor(self, cli_options):
258259
into a dict which will be given as kwargs to the app's .init() method.
259260
"""
260261
retval = dict(config_profile=cli_options.get('profile', None), config={})
261-
if cli_options.get('quiet', False):
262-
retval['config']['KEG_LOG_STREAM_ENABLED'] = False
262+
quiet = cli_options.get('quiet', 0)
263+
verbose = cli_options.get('verbose', 0)
264+
retval['config']['KEG_LOG_LEVEL'] = logging.WARNING + 10 * quiet - 10 * verbose
263265
return retval
264266

265267
def create_script_options(self):
266268
""" Create app level options, ideally that are used to configure the app itself. """
267269
return [
268270
click.Option(['--profile'], is_eager=True, default=None, callback=self.options_callback,
269271
help=_('Name of the configuration profile to use.'),),
270-
click.Option(['--quiet'], is_eager=True, is_flag=True, default=False,
271-
callback=self.options_callback,
272-
help=_('Set default logging level to logging.WARNING.')),
272+
click.Option(['--quiet', '-q'], is_eager=True, default=0,
273+
count=True, callback=self.options_callback,
274+
help=_('Increase logging level for reduced logging')),
275+
click.Option(['--verbose', '-v'], is_eager=True, default=0,
276+
count=True, callback=self.options_callback,
277+
help=_('Decrease logging level for increased logging')),
273278
click.Option(['--help-all'], is_eager=True, is_flag=True, expose_value=False,
274279
callback=self.help_all_callback,
275280
help=_('Show all commands with subcommands.')),

Diff for: keg/i18n/es/LC_MESSAGES/keg.mo

96 Bytes
Binary file not shown.

Diff for: keg/i18n/es/LC_MESSAGES/keg.po

+33-26
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: Keg 0.6.5\n"
99
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
10-
"POT-Creation-Date: 2021-01-26 10:25-0500\n"
10+
"POT-Creation-Date: 2021-02-15 17:12-0500\n"
1111
"PO-Revision-Date: 2018-08-16 18:25-0400\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language: es\n"
@@ -44,97 +44,101 @@ msgstr ""
4444
"No se pudieron encontrar activos relacionados para la plantilla: "
4545
"{template_name}"
4646

47-
#: keg/cli.py:63
47+
#: keg/cli.py:64
4848
msgid "Developer info and utils."
4949
msgstr "Información y utilidades del desarrollador."
5050

51-
#: keg/cli.py:72
51+
#: keg/cli.py:73
5252
msgid "List the routes defined for this app."
5353
msgstr "Enumera las rutas definidas para esta aplicación."
5454

55-
#: keg/cli.py:96
55+
#: keg/cli.py:97
5656
msgid "Show paths searched for a template."
5757
msgstr "Mostrar rutas buscadas para una plantilla."
5858

59-
#: keg/cli.py:112
59+
#: keg/cli.py:113
6060
msgid "List info related to config files, profiles, and values."
6161
msgstr ""
6262
"Lista de información relacionada con archivos de configuración, perfiles "
6363
"y valores."
6464

65-
#: keg/cli.py:121
65+
#: keg/cli.py:122
6666
msgid "Default config objects:"
6767
msgstr "Objetos de configuración predeterminados:"
6868

69-
#: keg/cli.py:125
69+
#: keg/cli.py:126
7070
msgid "Config file locations:"
7171
msgstr "Ubicaciones de archivos de configuración:"
7272

73-
#: keg/cli.py:130
73+
#: keg/cli.py:131
7474
msgid "Could not access the following config paths:"
7575
msgstr "No se pudo acceder a las siguientes rutas de configuración:"
7676

77-
#: keg/cli.py:134
77+
#: keg/cli.py:135
7878
msgid "Config objects used:"
7979
msgstr "Objetos de configuración utilizados:"
8080

81-
#: keg/cli.py:138
81+
#: keg/cli.py:139
8282
msgid "Resulting app config (including Flask defaults):"
8383
msgstr ""
8484
"Configuración de la aplicación resultante (incluidos los valores "
8585
"predeterminados del Flask)"
8686

87-
#: keg/cli.py:156
87+
#: keg/cli.py:157
8888
msgid "Lists database related sub-commands."
8989
msgstr "Enumera subcomandos relacionados con la base de datos."
9090

91-
#: keg/cli.py:163
91+
#: keg/cli.py:164
9292
msgid "Database not enabled for this app. No subcommands available."
9393
msgstr ""
9494
"La base de datos no está habilitada para esta aplicación. No hay "
9595
"subcomandos disponibles."
9696

97-
#: keg/cli.py:172
97+
#: keg/cli.py:173
9898
msgid "Create all db objects, send related events."
9999
msgstr "Crea todos los objetos db, envía eventos relacionados."
100100

101-
#: keg/cli.py:174
101+
#: keg/cli.py:175
102102
msgid "Clear DB of all data and drop all objects before init."
103103
msgstr "Borrar DB de todos los datos y soltar todos los objetos antes de init."
104104

105-
#: keg/cli.py:179
105+
#: keg/cli.py:180
106106
msgid "Database cleared and initialized"
107107
msgstr "Base de datos borrada e inicializada"
108108

109-
#: keg/cli.py:182
109+
#: keg/cli.py:183
110110
msgid "Database initialized"
111111
msgstr "Base de datos inicializada"
112112

113-
#: keg/cli.py:185
113+
#: keg/cli.py:186
114114
msgid "Clear DB of all data and drop all objects."
115115
msgstr "Borre la DB de todos los datos y suelte todos los objetos."
116116

117-
#: keg/cli.py:189
117+
#: keg/cli.py:190
118118
msgid "Database cleared"
119119
msgstr "Base de datos limpia"
120120

121-
#: keg/cli.py:253
121+
#: keg/cli.py:255
122122
msgid "Name of the configuration profile to use."
123123
msgstr "Nombre del perfil de configuración a usar."
124124

125-
#: keg/cli.py:256
126-
msgid "Set default logging level to logging.WARNING."
127-
msgstr "Establecer el nivel de registro predeterminado en logging.WARNING."
125+
#: keg/cli.py:258
126+
msgid "Increase logging level for reduced logging"
127+
msgstr "Aumentar el nivel de tala para reducir la tala"
128128

129-
#: keg/cli.py:259
129+
#: keg/cli.py:261
130+
msgid "Decrease logging level for increased logging"
131+
msgstr "Disminuir el nivel de registro para aumentar el registro."
132+
133+
#: keg/cli.py:264
130134
msgid "Show all commands with subcommands."
131135
msgstr "Mostrar todos los comandos con subcomandos."
132136

133-
#: keg/cli.py:288
137+
#: keg/cli.py:293
134138
msgid "Show help message."
135139
msgstr "Mostrar mensaje de ayuda."
136140

137-
#: keg/cli.py:290
141+
#: keg/cli.py:295
138142
msgid "Show this message and exit."
139143
msgstr "Mostrar este mensaje y salir."
140144

@@ -172,7 +176,7 @@ msgstr ""
172176
"{missing}, extra_keys = {extra_keys}, extra_pos = {extra_pos}. Argumentos"
173177
" disponibles: {calling_args}"
174178

175-
#: keg/web.py:140
179+
#: keg/web.py:137
176180
msgid "Unimplemented method {name}"
177181
msgstr "Método sin implementar {nombre}"
178182

@@ -318,3 +322,6 @@ msgstr "Excepción deliberada para fines de prueba"
318322
#~ msgid "Provider \"{provider}\" has not been registered."
319323
#~ msgstr "El proveedor \"{proveedor}\" no se ha registrado."
320324

325+
#~ msgid "Set default logging level to logging.WARNING."
326+
#~ msgstr "Establecer el nivel de registro predeterminado en logging.WARNING."
327+

Diff for: keg/i18n/keg.pot

+30-26
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#, fuzzy
77
msgid ""
88
msgstr ""
9-
"Project-Id-Version: Keg 0.8.4\n"
9+
"Project-Id-Version: Keg 0.8.6\n"
1010
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
11-
"POT-Creation-Date: 2021-01-26 10:25-0500\n"
11+
"POT-Creation-Date: 2021-02-15 17:12-0500\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -39,91 +39,95 @@ msgstr ""
3939
msgid "Could not find related assets for template: {template_name}"
4040
msgstr ""
4141

42-
#: keg/cli.py:63
42+
#: keg/cli.py:64
4343
msgid "Developer info and utils."
4444
msgstr ""
4545

46-
#: keg/cli.py:72
46+
#: keg/cli.py:73
4747
msgid "List the routes defined for this app."
4848
msgstr ""
4949

50-
#: keg/cli.py:96
50+
#: keg/cli.py:97
5151
msgid "Show paths searched for a template."
5252
msgstr ""
5353

54-
#: keg/cli.py:112
54+
#: keg/cli.py:113
5555
msgid "List info related to config files, profiles, and values."
5656
msgstr ""
5757

58-
#: keg/cli.py:121
58+
#: keg/cli.py:122
5959
msgid "Default config objects:"
6060
msgstr ""
6161

62-
#: keg/cli.py:125
62+
#: keg/cli.py:126
6363
msgid "Config file locations:"
6464
msgstr ""
6565

66-
#: keg/cli.py:130
66+
#: keg/cli.py:131
6767
msgid "Could not access the following config paths:"
6868
msgstr ""
6969

70-
#: keg/cli.py:134
70+
#: keg/cli.py:135
7171
msgid "Config objects used:"
7272
msgstr ""
7373

74-
#: keg/cli.py:138
74+
#: keg/cli.py:139
7575
msgid "Resulting app config (including Flask defaults):"
7676
msgstr ""
7777

78-
#: keg/cli.py:156
78+
#: keg/cli.py:157
7979
msgid "Lists database related sub-commands."
8080
msgstr ""
8181

82-
#: keg/cli.py:163
82+
#: keg/cli.py:164
8383
msgid "Database not enabled for this app. No subcommands available."
8484
msgstr ""
8585

86-
#: keg/cli.py:172
86+
#: keg/cli.py:173
8787
msgid "Create all db objects, send related events."
8888
msgstr ""
8989

90-
#: keg/cli.py:174
90+
#: keg/cli.py:175
9191
msgid "Clear DB of all data and drop all objects before init."
9292
msgstr ""
9393

94-
#: keg/cli.py:179
94+
#: keg/cli.py:180
9595
msgid "Database cleared and initialized"
9696
msgstr ""
9797

98-
#: keg/cli.py:182
98+
#: keg/cli.py:183
9999
msgid "Database initialized"
100100
msgstr ""
101101

102-
#: keg/cli.py:185
102+
#: keg/cli.py:186
103103
msgid "Clear DB of all data and drop all objects."
104104
msgstr ""
105105

106-
#: keg/cli.py:189
106+
#: keg/cli.py:190
107107
msgid "Database cleared"
108108
msgstr ""
109109

110-
#: keg/cli.py:253
110+
#: keg/cli.py:255
111111
msgid "Name of the configuration profile to use."
112112
msgstr ""
113113

114-
#: keg/cli.py:256
115-
msgid "Set default logging level to logging.WARNING."
114+
#: keg/cli.py:258
115+
msgid "Increase logging level for reduced logging"
116116
msgstr ""
117117

118-
#: keg/cli.py:259
118+
#: keg/cli.py:261
119+
msgid "Decrease logging level for increased logging"
120+
msgstr ""
121+
122+
#: keg/cli.py:264
119123
msgid "Show all commands with subcommands."
120124
msgstr ""
121125

122-
#: keg/cli.py:288
126+
#: keg/cli.py:293
123127
msgid "Show help message."
124128
msgstr ""
125129

126-
#: keg/cli.py:290
130+
#: keg/cli.py:295
127131
msgid "Show this message and exit."
128132
msgstr ""
129133

@@ -156,7 +160,7 @@ msgid ""
156160
"{calling_args}"
157161
msgstr ""
158162

159-
#: keg/web.py:140
163+
#: keg/web.py:137
160164
msgid "Unimplemented method {name}"
161165
msgstr ""
162166

Diff for: keg/tests/test_cli.py

+30-13
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,45 @@ def test_invoke(self):
9393
def test_no_commands_help_message(self):
9494
result = self.invoke()
9595
assert 'Usage: ' in result.output
96-
assert '--quiet Set default logging level to logging.WARNING' in result.output
96+
assert '-q, --quiet Increase logging level for reduced logging' in result.output
97+
assert '-v, --verbose Decrease logging level for increased logging' in result.output
9798
assert '--profile TEXT Name of the configuration profile to use.' in result.output
9899
assert '--help-all Show all commands with subcommands.' in result.output
99-
assert 'develop Developer info and utils.' in result.output
100+
assert 'develop Developer info and utils.' in result.output
100101
assert 'hello1' in result.output
101102

102-
def test_quiet(self):
103+
@pytest.mark.parametrize('args,enabled', (
104+
([], {'warning', 'error', 'critical'}),
105+
(['--quiet'], {'error', 'critical'}),
106+
(['--quiet', '--quiet'], {'critical'}),
107+
(['--quiet', '--quiet', '--quiet'], set()),
108+
(['--quiet', '--quiet', '--quiet', '--quiet'], set()),
109+
(['--verbose'], {'info', 'warning', 'error', 'critical'}),
110+
(['--verbose', '--verbose'], {'debug', 'info', 'warning', 'error', 'critical'}),
111+
(
112+
["--verbose", "--verbose", "--verbose"],
113+
{"debug", "info", "warning", "error", "critical"},
114+
),
115+
# Flags cancel each other out
116+
(['--quiet', '--verbose'], {'warning', 'error', 'critical'}),
117+
))
118+
def test_loglevel(self, args, enabled):
103119
# the asserts for these tests are in keg_apps.cli2.cli
104-
result = self.invoke('--quiet', 'is-quiet')
120+
levels = {'debug', 'info', 'warning', 'error', 'critical'}
121+
disabled = levels - enabled
122+
result = self.invoke(*args, 'test-log-level')
105123
assert 'printed foo' in result.output
106-
assert 'logged foo' not in result.output
107-
108-
result = self.invoke('is-not-quiet')
109-
assert 'printed foo' in result.output
110-
assert 'logged foo' in result.output
124+
for level in disabled:
125+
assert f'{level} logged foo' not in result.output
126+
for level in enabled:
127+
assert f'{level} logged foo' in result.output
111128

112129
def test_help_all(self):
113130
expected_lines = [
114-
'Usage', '', 'Options', '--profile', '--quiet', '--help-all', '--help',
115-
'Commands', 'develop', 'Commands', 'config', 'db', 'Commands', 'clear',
116-
'init', 'routes',
117-
'run', 'shell', 'templates', 'hello1', 'is-not-quiet', 'is-quiet', 'reverse',
131+
'Usage', '', 'Options', '--profile', '-q, --quiet', '-v, --verbose',
132+
'--help-all', '--help', 'Commands', 'develop', 'Commands', 'config',
133+
'db', 'Commands', 'clear', 'init', 'routes',
134+
'run', 'shell', 'templates', 'hello1', 'reverse', 'test-log-level',
118135
''
119136
]
120137
result = self.invoke('--help-all')

0 commit comments

Comments
 (0)