Switch logging config to ini format

Implement #61

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
Hiroshi Miura
2019-11-18 16:09:07 +09:00
parent 5c110461ca
commit 6ab2a1fc6e
6 changed files with 47 additions and 42 deletions

View File

@@ -28,8 +28,6 @@ import os
import platform import platform
import sys import sys
import yaml
from aqt.archives import QtArchives, ToolArchives from aqt.archives import QtArchives, ToolArchives
from aqt.installer import QtInstaller from aqt.installer import QtInstaller
@@ -141,7 +139,7 @@ class Cli():
parser = argparse.ArgumentParser(prog='aqt', description='Installer for Qt SDK.', parser = argparse.ArgumentParser(prog='aqt', description='Installer for Qt SDK.',
formatter_class=argparse.RawTextHelpFormatter, add_help=True) formatter_class=argparse.RawTextHelpFormatter, add_help=True)
parser.add_argument('--logging-conf', type=argparse.FileType('r'), parser.add_argument('--logging-conf', type=argparse.FileType('r'),
nargs=1, help="Specify logging configuration YAML file.") nargs=1, help="Logging configuration ini file.")
parser.add_argument('--logger', nargs=1, help="Specify logger name") parser.add_argument('--logger', nargs=1, help="Specify logger name")
parser.add_argument('--dry-run', action='store_true', help='Dry run operations.') parser.add_argument('--dry-run', action='store_true', help='Dry run operations.')
subparsers = parser.add_subparsers(title='subcommands', description='Valid subcommands', subparsers = parser.add_subparsers(title='subcommands', description='Valid subcommands',
@@ -198,10 +196,8 @@ class Cli():
elif envconf is not None: elif envconf is not None:
conf = envconf conf = envconf
if conf is None or not os.path.exists(conf): if conf is None or not os.path.exists(conf):
conf = os.path.join(os.path.dirname(__file__), 'logging.yml') conf = os.path.join(os.path.dirname(__file__), 'logging.ini')
with open(conf, 'r') as f: logging.config.fileConfig(conf)
log_config = yaml.safe_load(f.read())
logging.config.dictConfig(log_config)
if args.logger is not None: if args.logger is not None:
self.logger = logging.getLogger(args.logger) self.logger = logging.getLogger(args.logger)
else: else:

42
aqt/logging.ini Normal file
View File

@@ -0,0 +1,42 @@
[loggers]
keys=root,aqt
[logger_root]
level=NOTSET
handlers=console
[logger_aqt]
level=INFO
handlers=console,file
propagate=1
qualname=aqt
[formatters]
keys=verbose,simple,brief
[formatter_verbose]
format=%(asctime)s - %(name)s - %(levelname)s - %(module)s %(thread)d %(message)s
class=logging.Formatter
[formatter_simple]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
class=logging.Formatter
[formatter_brief]
format=%(message)s
class=logging.Formatter
[handlers]
keys=console,file
[handler_console]
level=WARN
class=logging.StreamHandler
formatter=brief
args=(sys.stdout,)
[handler_file]
level=INFO
class=logging.FileHandler
formatter=simple
args=('aqtinstall.log', 'a')

View File

@@ -1,32 +0,0 @@
version: 1
disable_existing_loggers: False
formatters:
simple:
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
brief:
format: '%(message)s'
handlers:
console:
class: logging.StreamHandler
level: WARN
formatter: brief
stream: ext://sys.stdout
file:
class: logging.FileHandler
level: INFO
formatter: simple
filename: aqtinstall.log
encoding: utf-8
loggers:
aqt:
level: ERROR
handler: [console]
propagate: yes
root:
level: INFO
handlers: [console, file]

View File

@@ -7,4 +7,3 @@ flake8
wheel wheel
twine twine
py7zr>=0.4.1 ; python_version > '3.5' py7zr>=0.4.1 ; python_version > '3.5'
pyyaml

View File

@@ -21,7 +21,7 @@ setup(name='aqtinstall',
author_email='miurahr@linux.com', author_email='miurahr@linux.com',
packages=["aqt"], packages=["aqt"],
package_data={'aqt': ['*.yml', "*.json", "*.ini"]}, package_data={'aqt': ['*.yml', "*.json", "*.ini"]},
install_requires=['requests', 'six', 'py7zr', 'pyyaml'], install_requires=['requests', 'six', 'py7zr'],
extras_require={'dev': ['pytest', 'pytest-pep8', 'pytest-cov', 'flake8']}, extras_require={'dev': ['pytest', 'pytest-pep8', 'pytest-cov', 'flake8']},
scripts=["bin/aqt"], scripts=["bin/aqt"],
classifiers=[ classifiers=[

View File

@@ -11,7 +11,7 @@ def test_cli_help(capsys):
"optional arguments:\n", "optional arguments:\n",
" -h, --help show this help message and exit\n", " -h, --help show this help message and exit\n",
" --logging-conf LOGGING_CONF\n", " --logging-conf LOGGING_CONF\n",
" Specify logging configuration YAML file.\n", " Logging configuration ini file.\n",
" --logger LOGGER Specify logger name\n", " --logger LOGGER Specify logger name\n",
" --dry-run Dry run operations.\n", " --dry-run Dry run operations.\n",
"\n", "\n",