Skip to content

Commit

Permalink
Reformatted and added color to logger messages. (#252)
Browse files Browse the repository at this point in the history
Closes #248 

Added color to logging and converted some info messages to debug.

added colors and cleaned up logger

corrected formatting

added to dependencies

reverted message log level change

added debug format

debug logging format now works

flake8 fix
  • Loading branch information
ben-bay committed Apr 24, 2020
1 parent 418d249 commit 60d5175
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
3 changes: 1 addition & 2 deletions maestrowf/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
LOGGER = logging.getLogger(__name__)

# Formatting of logger.
LFORMAT = "%(asctime)s - %(name)s:%(funcName)s:%(lineno)s - " \
"%(levelname)s - %(message)s"
LFORMAT = "[%(asctime)s: %(levelname)s] %(message)s"


def setup_logging(name, output_path, log_lvl=2, log_path=None,
Expand Down
6 changes: 3 additions & 3 deletions maestrowf/datastructures/core/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def __init__(self, name, description,
self._out_path = out_path
self._meta_path = os.path.join(out_path, "meta")

LOGGER.info("OUTPUT_PATH = %s", out_path)
LOGGER.debug("OUTPUT_PATH = %s", out_path)
# Flag the study as not having been set up and add the source node.
self._issetup = False
self.add_node(SOURCE, None)
Expand Down Expand Up @@ -376,7 +376,7 @@ def walk_study(self, src=SOURCE):
def setup_workspace(self):
"""Set up the study's main workspace directory."""
try:
LOGGER.info("Setting up study workspace in '%s'", self._out_path)
LOGGER.debug("Setting up study workspace in '%s'", self._out_path)
create_parentdir(self._out_path)
except Exception as e:
LOGGER.error(e.args)
Expand All @@ -386,7 +386,7 @@ def setup_environment(self):
"""Set up the environment by acquiring outside dependencies."""
# Set up the environment if it hasn't been already.
if not self.environment.is_set_up:
LOGGER.info("Environment is setting up.")
LOGGER.debug("Environment is setting up.")
self.environment.acquire_environment()

def configure_study(self, submission_attempts=1, restart_limit=1,
Expand Down
2 changes: 1 addition & 1 deletion maestrowf/datastructures/core/studyenvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def acquire_environment(self):
LOGGER.info("Environment already set up. Returning.")
return

LOGGER.info("Acquiring dependencies")
LOGGER.debug("Acquiring dependencies")
for dependency, value in self.dependencies.items():
LOGGER.info("Acquiring -- %s", dependency)
value.acquire(substitutions=self.substitutions.values())
Expand Down
11 changes: 8 additions & 3 deletions maestrowf/maestro.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@
LOG_UTIL = LoggerUtility(LOGGER)

# Configuration globals
LFORMAT = "%(asctime)s - %(name)s:%(funcName)s:%(lineno)s - " \
"%(levelname)s - %(message)s"
DEBUG_FORMAT = "[%(asctime)s: %(levelname)s] " \
"[%(module)s: %(lineno)d] %(message)s"
LFORMAT = "[%(asctime)s: %(levelname)s] %(message)s"
ACCEPTED_INPUT = set(["yes", "y"])


Expand Down Expand Up @@ -409,7 +410,11 @@ def main():

# If we have requested to log stdout, set it up to be logged.
if args.logstdout:
LOG_UTIL.configure(LFORMAT, args.debug_lvl)
if args.debug_lvl == 1:
lformat = DEBUG_FORMAT
else:
lformat = LFORMAT
LOG_UTIL.configure(lformat, args.debug_lvl)

LOGGER.info("INFO Logging Level -- Enabled")
LOGGER.warning("WARNING Logging Level -- Enabled")
Expand Down
6 changes: 5 additions & 1 deletion maestrowf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"""A collection of more general utility functions."""

from collections import OrderedDict
import coloredlogs
import logging
import os
import string
Expand Down Expand Up @@ -271,14 +272,17 @@ def __init__(self, logger):
"""
self._logger = logger

def configure(self, log_format, log_lvl=2):
def configure(self, log_format, log_lvl=2, colors=True):
"""
Configures the general logging facility.
:param log_format: String containing the desired logging format.
:param log_lvl: Integer level (1-5) to set the logger to.
"""
logging.basicConfig(level=self.map_level(log_lvl), format=log_format)
if colors:
coloredlogs.install(level=self.map_level(log_lvl),
logger=self._logger, fmt=log_format)

def add_stream_handler(self, log_format, log_lvl=2):
"""
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tabulate
enum34; python_version<'3.4'
dill
jsonschema>=3.2.0
coloredlogs
-e .

fabric
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"enum34 ; python_version<'3.4'",
"dill",
"jsonschema>=3.2.0",
"coloredlogs",
],
extras_require={},
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 60d5175

Please sign in to comment.