Skip to content

Commit adc3beb

Browse files
committed
Removed argconfparse dependency, better conf in yaml.
1 parent c165eff commit adc3beb

File tree

6 files changed

+31
-14
lines changed

6 files changed

+31
-14
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
*.pyc
2+
dist
3+
.idea
4+
simpledaemonlog.egg-info

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
argconfparse
21
pyyaml
2+
colorlog

setup.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44
situations and has been made available for easy reuse with different daemons.
55
"""
66

7-
from setuptools import setup
7+
from setuptools import setup, find_packages
8+
9+
import simpledaemonlog
810

911
doclines = __doc__.split("\n")
1012

1113
setup(name='simpledaemonlog',
12-
version='0.1.0',
14+
version=simpledaemonlog.version,
1315
description='Set up simple logging for a python daemon.',
1416
long_description='\n'.join(doclines[2:]),
1517
url='http://github.com/proactivity-lab/python-simpledaemonlog',
1618
author='Raido Pahtma',
1719
author_email='raido.pahtma@ttu.ee',
1820
license='MIT',
1921
platforms=["any"],
20-
install_requires=["pyyaml", "argconfparse"],
21-
packages=['simpledaemonlog'],
22+
install_requires=["pyyaml", "colorlog"],
23+
packages=find_packages(),
2224
zip_safe=False)

simpledaemonlog/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""__init__.py: Module init."""
2+
3+
from .logsetup import version
4+
5+
__author__ = "Raido Pahtma"
6+
__license__ = "MIT"

simpledaemonlog/daemonarguments.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
"""daemonarguments.py: Common options for daemons with argconfparse and simpledaemonlog."""
1+
"""daemonarguments.py: Common argparse options for daemons with simpledaemonlog."""
22

33
from simpledaemonlog import logsetup
4-
from argconfparse.argconfparse import arg_str2bool
5-
64

75
__author__ = 'Raido Pahtma'
86
__license__ = "MIT"
97

108

9+
def arg_str2bool(v):
10+
""" Use this for boolean options, regular bool is always treated as True. """
11+
return v.lower() in ("yes", "y", "true", "t", "1")
12+
13+
1114
def add_daemon_arguments(parser):
1215
parser.add_argument("--daemon", default=False, type=arg_str2bool, help="Daemon mode, no logging to console.")
1316
parser.add_argument("-d", dest="daemon", action="store_true", help="Daemon mode, no logging to console.")

simpledaemonlog/logsetup.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
__author__ = 'Raido Pahtma'
1515
__license__ = "MIT"
1616

17+
version = "0.2.0"
1718

1819
DEFAULT_FORMAT_STRING = '%(asctime)s|%(levelname)8s|%(module)20s|%(lineno)4s| %(message)s'
1920
COLORED_FORMAT_STRING = '%(log_color)s%(asctime)s%(reset)s|%(module)20s|%(lineno)4s| %(log_color)s%(message)s'
@@ -77,7 +78,7 @@ def setup_console(level=logging.NOTSET, fs=DEFAULT_FORMAT_STRING, settings=None,
7778
formatter = logging.Formatter(fs)
7879

7980
console.setFormatter(formatter)
80-
console.setLevel(level)
81+
console.setLevel(logging.NOTSET)
8182

8283
rootlogger = logging.getLogger("")
8384
rootlogger.setLevel(min(level, rootlogger.getEffectiveLevel()))
@@ -102,17 +103,19 @@ def setup_file(application_name, logdir="log", level=logging.NOTSET, fs=DEFAULT_
102103
loglatest = "log_{}_latest.txt".format(application_name)
103104
logfilepath = os.path.join(logdir, logfilename)
104105
loglinkpath = os.path.join(logdir, loglatest)
105-
logfile = logging.handlers.TimedRotatingFileHandler(logfilepath, when="W6", backupCount=backups)
106-
107-
if os.path.islink(loglinkpath):
108-
os.unlink(loglinkpath)
106+
if backups:
107+
logfile = logging.handlers.TimedRotatingFileHandler(logfilepath, when="W6", backupCount=backups)
108+
else:
109+
logfile = logging.FileHandler(logfilepath)
109110

110111
if hasattr(os, "symlink"):
112+
if os.path.islink(loglinkpath):
113+
os.unlink(loglinkpath)
111114
os.symlink(logfilename, loglinkpath)
112115

113116
formatter = logging.Formatter(fs)
114117
logfile.setFormatter(formatter)
115-
logfile.setLevel(level)
118+
logfile.setLevel(logging.NOTSET)
116119

117120
rootlogger = logging.getLogger("")
118121
rootlogger.setLevel(min(level, rootlogger.getEffectiveLevel()))

0 commit comments

Comments
 (0)