Skip to content

Commit

Permalink
Merge pull request #64 from Rajendra-R/debug_issue
Browse files Browse the repository at this point in the history
#61 resolve the debug mode issue
  • Loading branch information
prashanthellina authored Apr 13, 2018
2 parents c46d822 + ee4c14d commit 79dc23c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 5 additions & 1 deletion basescript/basescript.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, args=None):

self.subcommands = self.parser.add_subparsers(title='commands')
self.subcommands.dest = 'commands'
self.subcommands.required = True
self.define_subcommands(self.subcommands)
self.subcommand_run = self.subcommands.add_parser('run')
self.subcommand_run.set_defaults(func=self.run)
Expand All @@ -37,10 +38,13 @@ def __init__(self, args=None):
if self.args.metric_grouping_interval is None:
self.args.metric_grouping_interval = 0

else:
if not self.args.log_level:
self.args.log_level = 'info'
self.args.metric_grouping_interval = self.METRIC_GROUPING_INTERVAL

if self.args.metric_grouping_interval is None:
self.args.metric_grouping_interval = self.METRIC_GROUPING_INTERVAL

self.log = init_logger(
fmt=self.args.log_format,
quiet=self.args.quiet,
Expand Down
12 changes: 5 additions & 7 deletions basescript/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
_GLOBAL_LOG_CONFIGURED = False

HOSTNAME = socket.gethostname()
METRIC_GROUPING_INTERVAL = 1 # one second
METRICS_STATE = {}
METRICS_STATE_LOCK = Lock()

Expand Down Expand Up @@ -242,11 +241,9 @@ def define_log_renderer(fmt, fpath, quiet):
# it must accept a logger, method_name and event_dict (just like processors)
# but must return the rendered string, not a dictionary.
# TODO tty logic
if fmt == "json":
return structlog.processors.JSONRenderer()

if fmt == "pretty":
return structlog.dev.ConsoleRenderer()
if fmt:
return structlog.processors.JSONRenderer()

if fpath is not None:
return structlog.processors.JSONRenderer()
Expand Down Expand Up @@ -326,9 +323,10 @@ def metrics_grouping_processor(logger_class, log_method, event):
for fk, fv in fields:
favg = sfields.get(fk, 0.0)
favg = (favg * num + fv) / (num + 1) #moving average
state['num'] += 1
sfields[fk] = favg

state['num'] += 1

METRICS_STATE[key] = state
finally:
METRICS_STATE_LOCK.release()
Expand Down Expand Up @@ -439,7 +437,7 @@ def init_logger(
fpath=None,
pre_hooks=None,
post_hooks=None,
metric_grouping_interval=METRIC_GROUPING_INTERVAL
metric_grouping_interval=None
):

global LOG
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_long_description():

long_description = get_long_description()

version = '0.2.4'
version = '0.2.5'
setup(
name="basescript",
version=version,
Expand Down

0 comments on commit 79dc23c

Please sign in to comment.