Skip to content

Commit

Permalink
Keep logging verbosity and output format on namespace. (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott authored Oct 25, 2018
1 parent e3ba37f commit d5d76a8
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 23 deletions.
15 changes: 1 addition & 14 deletions knack/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from logging.handlers import RotatingFileHandler

from .util import CtxTypeError, ensure_dir
from .events import EVENT_INVOKER_PRE_CMD_TBL_CREATE, EVENT_PARSER_GLOBAL_CREATE
from .events import EVENT_PARSER_GLOBAL_CREATE

CLI_LOGGER_NAME = 'cli'

Expand Down Expand Up @@ -98,18 +98,6 @@ def on_global_arguments(_, **kwargs):
arg_group.add_argument(CLILogging.DEBUG_FLAG, dest='_log_verbosity_debug', action='store_true',
help='Increase logging verbosity to show all debug logs.')

@staticmethod
def remove_logger_flags(_, **kwargs):
args = kwargs.get('args')
try:
args.remove(CLILogging.VERBOSE_FLAG)
except ValueError:
pass
try:
args.remove(CLILogging.DEBUG_FLAG)
except ValueError:
pass

def __init__(self, name, cli_ctx=None):
"""
Expand All @@ -128,7 +116,6 @@ def __init__(self, name, cli_ctx=None):
self.console_log_format = CLILogging._get_console_log_format()
self.cli_ctx = cli_ctx
self.cli_ctx.register_event(EVENT_PARSER_GLOBAL_CREATE, CLILogging.on_global_arguments)
self.cli_ctx.register_event(EVENT_INVOKER_PRE_CMD_TBL_CREATE, CLILogging.remove_logger_flags)

def configure(self, args):
""" Configure the loggers with the appropriate log level etc.
Expand Down
2 changes: 0 additions & 2 deletions knack/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ def handle_output_argument(cli_ctx, **kwargs):
args = kwargs.get('args')
# Set the output type for this invocation
cli_ctx.invocation.data['output'] = getattr(args, OutputProducer.ARG_DEST)
# We've handled the argument so remove it
delattr(args, OutputProducer.ARG_DEST)

def __init__(self, cli_ctx=None):
""" Manages the production of output from the result of a command invocation
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from codecs import open
from setuptools import setup, find_packages

VERSION = '0.4.4'
VERSION = '0.4.5'

DEPENDENCIES = [
'argcomplete',
Expand Down
6 changes: 0 additions & 6 deletions tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ def test_logging_argument_registrations(self):
parser_arg_group_mock.add_argument.assert_any_call(CLILogging.DEBUG_FLAG, dest=mock.ANY, action=mock.ANY,
help=mock.ANY)

def test_logging_arguments_removed(self):
arguments = [CLILogging.VERBOSE_FLAG, CLILogging.DEBUG_FLAG]
self.mock_ctx.raise_event(EVENT_INVOKER_PRE_CMD_TBL_CREATE, args=arguments)
# After the event is raised, the arguments should have been removed
self.assertFalse(arguments)


class TestLoggingLevel(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit d5d76a8

Please sign in to comment.