7 Commits
Author SHA1 Message Date
spacefreak e8fe7915c1 change gentoo ebuild version to 0.0.3 2020-11-09 22:18:57 +01:00
spacefreak 4726c17366 change README.md 2020-11-09 22:18:00 +01:00
spacefreak 1a8e7ccb92 improve logging config 2020-11-09 22:15:19 +01:00
spacefreak dbe7ba83b6 change README.md 2020-11-09 21:23:10 +01:00
spacefreak 56a8586168 change README.md 2020-11-09 20:39:18 +01:00
spacefreak 977f06436d fix gentoo ebuilds 2020-11-09 20:16:04 +01:00
spacefreak 2441ba2048 change version to 0.0.3 2020-11-09 20:12:18 +01:00
5 changed files with 62 additions and 28 deletions
+16 -24
View File
@@ -172,42 +172,34 @@ w = Watch(
rec=False, rec=False,
auto_add=False) auto_add=False)
pyinotifyd.add_watch( pyinotifyd.add_watch(watch=w)
watch=w)
``` ```
## Logging ## Logging
Pythons [logging](https://docs.python.org/3/howto/logging.html) framework is used to log messages (see https://docs.python.org/3/howto/logging.html). Pythons [logging](https://docs.python.org/3/howto/logging.html) framework is used to log messages (see https://docs.python.org/3/howto/logging.html).
The following loglevels are available:
Configure the global loglevel. This is the default: * DEBUG
* INFO
* WARNING
* ERROR
* CRITICAL
```python ```python
logging.getLogger().setLevel(logging.WARNING) # Configure global loglevel
setLoglevel(INFO)
``` ```
It is possible to configure the loglevel per *logname*. This is an example for logname **sched**: Configure loglevel per *logname*.
```python ```python
logging.getLogger("sched").setLevel(logging.INFO) setLoglevel(INFO, logname="daemon")
``` ```
### Syslog ### Syslog
Add this to your config file to send log messages to a local syslog server. Send log messages to the local syslog server.
```python ```python
# send log messages to the Unix socket of the syslog server. # Enable logging to local syslog server (/dev/log). Use *address* to specify a different target.
syslog = logging.handlers.SysLogHandler( enableSyslog(loglevel=INFO, address="/dev/log")
address="/dev/log")
# set the log format of syslog messages # Enable syslog per logname
log_format = "pyinotifyd/%(name)s: %(message)s" enableSyslog(lglevel=INFO, name="daemon")
syslog.setFormatter(
logging.Formatter(formatter)
# set the log level for syslog messages
syslog.setLevel(logging.INFO)
# enable syslog for pyinotifyd
logging.getLogger().addHandler(syslog)
# or enable syslog just for the daemon
logging.getLogger("daemon").addHandler(syslog)
``` ```
# Examples # Examples
@@ -38,7 +38,7 @@ python_install_all() {
dodir /etc/${PN} dodir /etc/${PN}
insinto /etc/${PN} insinto /etc/${PN}
newins ${PN}/misc/config.py.example config.py newins ${PN}/misc/config.py.default config.py
use systemd && systemd_dounit ${PN}/misc/${PN}.service use systemd && systemd_dounit ${PN}/misc/${PN}.service
@@ -38,7 +38,7 @@ python_install_all() {
dodir /etc/${PN} dodir /etc/${PN}
insinto /etc/${PN} insinto /etc/${PN}
newins ${PN}/misc/config.py.example config.py newins ${PN}/misc/config.py.default config.py
use systemd && systemd_dounit ${PN}/misc/${PN}.service use systemd && systemd_dounit ${PN}/misc/${PN}.service
+20 -2
View File
@@ -34,7 +34,23 @@ from pyinotify import ProcessEvent
from pyinotifyd._install import install, uninstall from pyinotifyd._install import install, uninstall
from pyinotifyd.scheduler import TaskScheduler, Cancel from pyinotifyd.scheduler import TaskScheduler, Cancel
__version__ = "0.0.2" __version__ = "0.0.3"
def setLoglevel(loglevel, logname=None):
logger = logging.getLogger(logname)
logger.setLevel(loglevel)
def enableSyslog(loglevel=None, address="/dev/log", logname=None):
logger = logging.getLogger(logname)
syslog = logging.handlers.SysLogHandler(address=address)
syslog.setFormatter(
logging.Formatter(f"{Pyinotifyd.name}/%(name)s: %(message)s"))
if loglevel:
syslog.setLevel(loglevel)
logger.addHandler(syslog)
class _SchedulerList: class _SchedulerList:
@@ -184,8 +200,10 @@ class Pyinotifyd:
def from_cfg_file(config_file): def from_cfg_file(config_file):
config = {} config = {}
name = Pyinotifyd.name name = Pyinotifyd.name
exec("import logging", {}, config) exec("from logging import DEBUG, INFO, WARNING, ERROR, CRITICAL",
{}, config)
exec(f"from {name} import Pyinotifyd, Watch", {}, config) exec(f"from {name} import Pyinotifyd, Watch", {}, config)
exec(f"from {name} import setLoglevel, enableSyslog", {}, config)
exec(f"from {name}.scheduler import *", {}, config) exec(f"from {name}.scheduler import *", {}, config)
with open(config_file, "r") as fh: with open(config_file, "r") as fh:
exec(fh.read(), {}, config) exec(fh.read(), {}, config)
+24
View File
@@ -82,3 +82,27 @@
# event_map = event_map, # event_map = event_map,
# rec=True, # rec=True,
# auto_add=True) # auto_add=True)
################
# Log config #
################
# set global loglevel
#setLoglevel(DEBUG)
# set loglevel per logname
#setLoglevel(
# DEBUG,
# logname="daemon")
# enable syslog
#enableSyslog(
# loglevel=DEBUG,
# address="/dev/log")
# enable syslog per logname
#enableSyslog(
# loglevel=DEBUG,
# address="/dev/log",
# logname="sched")