Commit b48fe6ea authored by Flavio TARSETTI's avatar Flavio TARSETTI

Merge branch 'improve_logging_setup' into 'master'

Improve logging setup

See merge request !85
parents 06e3339b 88b0e0b2
Pipeline #38026 passed with stages
in 9 minutes and 8 seconds
......@@ -264,7 +264,7 @@ class Selector(object):
with open(self.path, "rt") as f:
data = simplejson.load(f, object_pairs_hook=collections.OrderedDict)
except simplejson.JSONDecodeError:
logger.warn(
logger.warning(
"invalid state file at `%s' - removing and re-starting...", self.path
)
from beat.core.utils import safe_rmfile
......@@ -515,7 +515,7 @@ def display_local_list(prefix, asset_type):
if "description" in contents:
logger.extra(2 * " " + contents["description"])
except simplejson.JSONDecodeError:
logger.warn(2 * " " + "(!) invalid JSON file")
logger.warning(2 * " " + "(!) invalid JSON file")
if len(names) != 1:
logger.extra("%d %s found", len(names), TYPE_PLURAL[asset_type])
......@@ -694,7 +694,7 @@ def check_one(prefix, asset_type, name):
if not o.valid:
logger.info("%s/%s [invalid]", TYPE_PLURAL[asset_type], name)
for e in o.errors:
logger.warn(" * %s", e)
logger.warning(" * %s", e)
return 1
else:
......@@ -1394,7 +1394,7 @@ def push(
)
if not candidates:
logger.warn("No new candidates for upload were found")
logger.warning("No new candidates for upload were found")
return 0
# flush all final candidates
......@@ -1531,7 +1531,7 @@ def dot_diagram(prefix, asset_type, names, path, formats):
return 1
if not obj.valid:
logger.warn(
logger.warning(
"%s/%s is not valid - skipping it", TYPE_PLURAL[asset_type], name
)
continue
......@@ -1539,7 +1539,7 @@ def dot_diagram(prefix, asset_type, names, path, formats):
try:
diagram = obj.dot_diagram()
except Exception as e:
logger.warn(
logger.warning(
"%s/%s cannot be drawn: %s - skipping it",
TYPE_PLURAL[asset_type],
name,
......
......@@ -35,7 +35,6 @@
import click
import logging
from . import common
from . import commands
......@@ -46,9 +45,6 @@ from .click_helper import AssetCommand
from .click_helper import AssetInfo
logger = logging.getLogger(__name__)
def pull_impl(webapi, prefix, names, force, indentation, format_cache):
"""Copies plotterparameters from the server.
......
......@@ -13,35 +13,65 @@ from ..config import Configuration
logging.EXTRA = 15
logging.addLevelName(logging.EXTRA, "EXTRA")
def _extra(self, message, *args, **kws):
if self.isEnabledFor(logging.EXTRA):
self._log(logging.EXTRA, message, args, **kws)
logging.Logger.extra = _extra
@with_plugins(pkg_resources.iter_entry_points('beat.cli'))
@with_plugins(pkg_resources.iter_entry_points("beat.cli"))
@click.group(cls=AliasedGroup)
@click.option('-T', '--test-mode', help='Assume test mode and doesn\'t setup '
'the logging module', default=False, is_flag=True)
@click.option('-p', '--prefix',
help='Overrides the prefix of your local data. '
'If not set use the value from your RC file',
type=click.STRING)
@click.option('-c', '--cache',
help='Overrides the cache prefix. If not set, use the value '
'from your RC file', type=click.STRING)
@click.option('-t', '--token', help='Overrides the user token for server '
'operations. If not set, use the value from your RC file.',
type=click.STRING)
@click.option('-u', '--user', help='Overrides the user name on the remote '
'platform. If not set, use the value from your RC file.',
type=click.STRING)
@click.option('-m', '--platform', help='The URL of the BEAT platform to '
'access.', type=click.STRING)
@click.option('-e', '--editor',
help='Overrides the user editor to edit local files. If not '
'set, use the value from your environment. There are no '
'defaults for this option.', type=click.STRING)
@click.option(
"-T",
"--test-mode",
help="Assume test mode and doesn't setup " "the logging module",
default=False,
is_flag=True,
)
@click.option(
"-p",
"--prefix",
help="Overrides the prefix of your local data. "
"If not set use the value from your RC file",
type=click.STRING,
)
@click.option(
"-c",
"--cache",
help="Overrides the cache prefix. If not set, use the value " "from your RC file",
type=click.STRING,
)
@click.option(
"-t",
"--token",
help="Overrides the user token for server "
"operations. If not set, use the value from your RC file.",
type=click.STRING,
)
@click.option(
"-u",
"--user",
help="Overrides the user name on the remote "
"platform. If not set, use the value from your RC file.",
type=click.STRING,
)
@click.option(
"-m",
"--platform",
help="The URL of the BEAT platform to " "access.",
type=click.STRING,
)
@click.option(
"-e",
"--editor",
help="Overrides the user editor to edit local files. If not "
"set, use the value from your environment. There are no "
"defaults for this option.",
type=click.STRING,
)
@click.version_option()
@verbosity_option()
@click.pass_context
......@@ -49,32 +79,32 @@ def main(ctx, test_mode, prefix, cache, user, token, platform, editor):
"""The main command line interface for beat cmdline. Look below for available
commands."""
ctx.meta['--prefix'] = prefix
ctx.meta['--cache'] = cache
ctx.meta['--user'] = user
ctx.meta['--token'] = token
ctx.meta['--platform'] = platform
ctx.meta['--editor'] = editor
ctx.meta["--prefix"] = prefix
ctx.meta["--cache"] = cache
ctx.meta["--user"] = user
ctx.meta["--token"] = token
ctx.meta["--platform"] = platform
ctx.meta["--editor"] = editor
# Check that we are in a BEAT working folder
config = Configuration(ctx.meta)
# Sets up the central logger
if not test_mode:
logger = logging.getLogger()
logger.setLevel(logging.DEBUG) #lets everything pass by default
verbosity = ctx.meta["verbosity"]
# Console logging
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO) # default level
format_str = "%(message)s"
if 'verbosity' in ctx.meta and ctx.meta['verbosity'] > 2:
if verbosity > 2:
format_str = "[%(asctime)s - %(name)s] %(levelname)s: %(message)s"
formatter = logging.Formatter(format_str, datefmt="%d/%b/%Y %H:%M:%S")
console_handler.setFormatter(formatter)
logger = logging.getLogger("beat")
logger.addHandler(console_handler)
# Execute the command
ctx.meta['config'] = config
ctx.meta["config"] = config
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment