diff --git a/.travis.yml b/.travis.yml index dd4957e..fe4f5c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,8 +19,8 @@ deploy: - basescript/utils.py - examples/adder.py - examples/helloworld.py - name: basescript-0.3.2 - tag_name: 0.3.2 + name: basescript-0.3.3 + tag_name: 0.3.3 true: repo: deep-compute/basescript - provider: pypi diff --git a/basescript/basescript.py b/basescript/basescript.py index ad63f2e..bc9962f 100644 --- a/basescript/basescript.py +++ b/basescript/basescript.py @@ -54,6 +54,7 @@ def __init__(self, args=None): pre_hooks=self.define_log_pre_format_hooks(), post_hooks=self.define_log_post_format_hooks(), metric_grouping_interval=self.args.metric_grouping_interval, + minimal=self.args.minimal, ) self._flush_metrics_q = log._force_flush_q @@ -169,6 +170,12 @@ def define_baseargs(self, parser): action="store_true", help="To run the code in debug mode", ) + parser.add_argument( + "--minimal", + default=False, + action="store_true", + help="Hide log keys such as id, host", + ) def define_args(self, parser): """ diff --git a/basescript/log.py b/basescript/log.py index 602133b..d851a75 100644 --- a/basescript/log.py +++ b/basescript/log.py @@ -263,6 +263,14 @@ def _structlog_default_keys_processor(logger_class, log_method, event): return event +def _structlog_minimal_processor(logger_class, log_method, event): + for key in ("host", "id", "type"): + if key in event: + event.pop(key) + + return event + + @keeprunning() def dump_metrics(log, interval): global METRICS_STATE @@ -358,7 +366,9 @@ def define_log_processors(): ] -def _configure_logger(fmt, quiet, level, fpath, processors, metric_grouping_interval): +def _configure_logger( + fmt, quiet, level, fpath, processors, metric_grouping_interval, minimal +): """ configures a logger when required write to stderr or a file """ @@ -376,6 +386,9 @@ def _configure_logger(fmt, quiet, level, fpath, processors, metric_grouping_inte if metric_grouping_interval: _processors.append(metrics_grouping_processor) + if minimal: + _processors.append(_structlog_minimal_processor) + streams = [] if fpath: @@ -418,6 +431,7 @@ def init_logger( fpath=None, processors=None, metric_grouping_interval=None, + minimal=False, ): """ fmt=pretty/json controls only stderr; file always gets json. @@ -434,7 +448,9 @@ def init_logger( if not fmt and not quiet: fmt = "pretty" if sys.stderr.isatty() else "json" - _configure_logger(fmt, quiet, level, fpath, processors, metric_grouping_interval) + _configure_logger( + fmt, quiet, level, fpath, processors, metric_grouping_interval, minimal + ) log = structlog.get_logger() log._force_flush_q = queue.Queue(maxsize=FORCE_FLUSH_Q_SIZE) diff --git a/setup.py b/setup.py index bfedc18..45bc624 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ def get_long_description(): long_description = get_long_description() -version = "0.3.2" +version = "0.3.3" setup( name="basescript", version=version,