Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept log level param on cactus cli #172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cactus/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# encoding: utf-8
import os
import sys
import logging
import time
import argparse
import colorama
Expand Down Expand Up @@ -104,6 +103,9 @@ def main():
subparser.add_argument('-c', '--config', action="append",
help='Add a config file you want to use')

subparser.add_argument('--log-level', dest='loglevel',
help='Set log level')

subparser.set_defaults(path = os.getcwd())

args = parser.parse_args()
Expand All @@ -113,9 +115,9 @@ def main():
if hasattr(args, 'config') and args.config is None: # We don't need config for create
args.config = ["config.json"]

setup_logging()
setup_logging(getattr(args, 'loglevel'))

args.target(**{k: v for k, v in vars(args).items() if k != 'target'})
args.target(**{k: v for k, v in vars(args).items() if k not in ['target', 'loglevel']})


if __name__ == "__main__":
Expand Down
12 changes: 6 additions & 6 deletions cactus/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ def format(self, record):

return json.dumps(data)

def setup_logging():
def setup_logging(level):

logger = logging.getLogger()
handler = logging.StreamHandler()

if not level:
level = 'INFO'
log_level = logging.getLevelName(level)

if os.environ.get('DESKTOPAPP'):
log_level = logging.INFO
log_format = '%(message)s'

handler.setFormatter(JsonFormatter())

else:

from colorlog import ColoredFormatter

log_level = logging.INFO


formatter = ColoredFormatter(
"%(log_color)s%(message)s",
datefmt=None,
Expand Down