Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8fe7915c1
|
||
|
|
4726c17366
|
||
|
|
1a8e7ccb92
|
||
|
|
dbe7ba83b6
|
||
|
|
56a8586168
|
||
|
|
977f06436d
|
||
|
|
2441ba2048
|
@@ -172,42 +172,34 @@ w = Watch(
|
||||
rec=False,
|
||||
auto_add=False)
|
||||
|
||||
pyinotifyd.add_watch(
|
||||
watch=w)
|
||||
pyinotifyd.add_watch(watch=w)
|
||||
```
|
||||
|
||||
## 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).
|
||||
|
||||
Configure the global loglevel. This is the default:
|
||||
The following loglevels are available:
|
||||
* DEBUG
|
||||
* INFO
|
||||
* WARNING
|
||||
* ERROR
|
||||
* CRITICAL
|
||||
```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
|
||||
logging.getLogger("sched").setLevel(logging.INFO)
|
||||
setLoglevel(INFO, logname="daemon")
|
||||
```
|
||||
|
||||
### 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
|
||||
# send log messages to the Unix socket of the syslog server.
|
||||
syslog = logging.handlers.SysLogHandler(
|
||||
address="/dev/log")
|
||||
# Enable logging to local syslog server (/dev/log). Use *address* to specify a different target.
|
||||
enableSyslog(loglevel=INFO, address="/dev/log")
|
||||
|
||||
# set the log format of syslog messages
|
||||
log_format = "pyinotifyd/%(name)s: %(message)s"
|
||||
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)
|
||||
# Enable syslog per logname
|
||||
enableSyslog(lglevel=INFO, name="daemon")
|
||||
```
|
||||
|
||||
# Examples
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ python_install_all() {
|
||||
|
||||
dodir /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
|
||||
|
||||
@@ -38,7 +38,7 @@ python_install_all() {
|
||||
|
||||
dodir /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
|
||||
|
||||
|
||||
+20
-2
@@ -34,7 +34,23 @@ from pyinotify import ProcessEvent
|
||||
from pyinotifyd._install import install, uninstall
|
||||
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:
|
||||
@@ -184,8 +200,10 @@ class Pyinotifyd:
|
||||
def from_cfg_file(config_file):
|
||||
config = {}
|
||||
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 setLoglevel, enableSyslog", {}, config)
|
||||
exec(f"from {name}.scheduler import *", {}, config)
|
||||
with open(config_file, "r") as fh:
|
||||
exec(fh.read(), {}, config)
|
||||
|
||||
@@ -82,3 +82,27 @@
|
||||
# event_map = event_map,
|
||||
# rec=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")
|
||||
|
||||
Reference in New Issue
Block a user