Commit af249dfc authored by Bram Daams's avatar Bram Daams
Browse files

default log level ERROR

parent e2d2bbcb
......@@ -6,6 +6,9 @@ __pycache__/
# C extensions
*.so
# config file
sch.conf
# Distribution / packaging
.Python
env/
......@@ -102,4 +105,4 @@ ENV/
.mypy_cache/
# IDE settings
.vscode/
\ No newline at end of file
.vscode/
......@@ -6,7 +6,7 @@
A cron shell wrapper for registering and updating cron jobs automatically in
[healthchecks](https://healthchecks.io) or your [own hosted copy of Healthchecks](https://github.com/healthchecks/healthchecks).
> warning: this software package should be considered "alpha"
> WARNING: once setup and configured, the code in this package runs as user specified in the cron jobs and is wrapped around the cron job commands. Errors in this package could prevent your cron jobs from being executed.
## Installation
......@@ -76,10 +76,16 @@ Create a configuration file `/etc/sch.conf` that looks like:
healthchecks_api_url = https://hc.example.com/api/v1/
healthchecks_api_key = xxmysecretkeyxx
```
And fill in the API URL and the key obtained from the Healthchecks project
settings block labeled "API Access".
Optionally, specify the log level in the configuration file:
``` ini
[sch]
loglevel = DEBUG
```
Possible values for loglevel are explained [here](https://docs.python.org/3/library/logging.html#levels). The default log level is `ERROR`.
## Monitoring cron jobs
Just decorate your existing cron tabs by specifying the alternative `sch`:
```
......
......@@ -22,6 +22,23 @@ import tzlocal
from crontabs import CronTabs
from . import __version__
def get_config():
"""
try loading the configuration file
"""
try:
my_config = configparser.ConfigParser()
my_config.read(['sch.conf', '/etc/sch.conf'])
except configparser.Error:
logging.error(
'Could not find/read/parse config'
'file sch.conf or /etc/sch.conf'
)
my_config = None
return my_config
HANDLER = logging.handlers.SysLogHandler('/dev/log')
FORMATTER = logging.Formatter(
'{name}/%(module)s.%(funcName)s:'
......@@ -29,8 +46,13 @@ FORMATTER = logging.Formatter(
)
HANDLER.setFormatter(FORMATTER)
ROOT = logging.getLogger()
# log level DEBUG
ROOT.setLevel(logging.DEBUG)
CONFIG = get_config()
try:
LEVEL = CONFIG.get('sch', 'loglevel')
ROOT.setLevel(LEVEL)
except configparser.Error:
ROOT.setLevel(logging.ERROR)
ROOT.addHandler(HANDLER)
......@@ -81,10 +103,8 @@ def get_hc_api():
try loading Healthchecks API url and key
and return an instance of Healthchecks or None if it failed
"""
config = get_config()
try:
config = configparser.ConfigParser()
config.read(['sch.conf', '/etc/sch.conf'])
url = config.get('hc', 'healthchecks_api_url')
key = config.get('hc', 'healthchecks_api_key')
......@@ -97,7 +117,6 @@ def get_hc_api():
except configparser.Error:
logging.error(
'Could not find/read/parse config'
'file sch.conf or /etc/sch.conf'
)
healthchecks = None
......@@ -195,7 +214,7 @@ def shell(command):
start_time = time.time()
# execute command
logging.debug(
logging.info(
"Executing shell commmand: %s (job.id=%s)",
command,
job.id,
......
Supports Markdown
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