Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8fe7915c1
|
||
|
|
4726c17366
|
||
|
|
1a8e7ccb92
|
||
|
|
dbe7ba83b6
|
||
|
|
56a8586168
|
||
|
|
977f06436d
|
||
|
|
2441ba2048
|
@@ -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
|
||||||
|
|||||||
+1
-1
@@ -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
@@ -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)
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user