Set logging level in config. Close #10

This commit is contained in:
Dmitry Petrov
2017-04-06 21:13:25 -07:00
parent e1ef7e2f5c
commit 78573e9aca
4 changed files with 50 additions and 16 deletions
+4 -1
View File
@@ -20,6 +20,9 @@ CacheDir = {}
StateDir = {}
Cloud = AWS
# Log levels: Debug, Info, Warning and Error
LogLevel = Info
[AWS]
AccessKeyId =
SecretAccessKey =
@@ -77,7 +80,7 @@ SecurityGroup = dvc-group'''
data_dir_path.mkdir()
cache_dir_path.mkdir()
state_dir_path.mkdir()
Logger.info('Directories {}, {} and {} were created'.format(
Logger.info('Directories {}/, {}/ and {}/ were created'.format(
data_dir_path.name,
cache_dir_path.name,
state_dir_path.name))
+4
View File
@@ -2,6 +2,7 @@ import os
import configparser
from dvc.exceptions import DvcException
from dvc.logger import Logger
class ConfigError(DvcException):
@@ -44,6 +45,9 @@ class Config(ConfigI):
raise ConfigError('Config file "{}" does not exist'.format(conf_file))
self._config.read(conf_file)
level = self._config['Global']['LogLevel']
Logger.set_level(level)
super(Config, self).__init__(self._config['Global']['DataDir'],
self._config['Global']['CacheDir'],
self._config['Global']['StateDir'])
+2 -2
View File
@@ -126,10 +126,10 @@ class GitWrapper(GitWrapperI):
def commit_all_changes_and_log_status(self, message):
statuses = self.commit_all_changes(message)
Logger.debug('[Git] A new commit {} was made in the current branch. Added files:'.format(
Logger.info('[Git] A new commit {} was made in the current branch. Added files:'.format(
self.curr_commit))
for status, file in statuses:
Logger.debug('[Git]\t{} {}'.format(status, file))
Logger.info('[Git]\t{} {}'.format(status, file))
pass
@staticmethod
+40 -13
View File
@@ -1,24 +1,51 @@
import sys
class Logger(object):
@staticmethod
def printing(msg):
print(u'{}'.format(msg))
DEFAULT_LEVEL = 2
LEVEL = DEFAULT_LEVEL
LEVEL_MAP = {
'debug': 1,
'info': 2,
'warn': 3,
'error': 4
}
@staticmethod
def warn(msg):
print(u'Warning. {}'.format(msg))
def set_level(level):
Logger.LEVEL = Logger.LEVEL_MAP.get(level.lower(), 'debug')
@staticmethod
def error(msg):
#sys.stderr.write('Error. {}\n'.format(msg))
print(u'Error. {}'.format(msg))
def is_debug():
return Logger.LEVEL <= 1
@staticmethod
def is_info():
return Logger.LEVEL <= 2
@staticmethod
def is_warn():
return Logger.LEVEL <= 3
@staticmethod
def is_error():
return Logger.LEVEL <= 4
@staticmethod
def debug(msg):
print(u'Debug. {}'.format(msg))
if Logger.is_debug():
print(u'Debug. {}'.format(msg))
@staticmethod
def info(msg):
print(u'Info. {}'.format(msg))
if Logger.is_info():
print(u'Info. {}'.format(msg))
@staticmethod
def warn(msg):
if Logger.is_warn():
print(u'Warning. {}'.format(msg))
@staticmethod
def error(msg):
if Logger.is_error():
print(u'Error. {}'.format(msg))