2017-12-16 18:59:33 +01:00
|
|
|
|
# pyruse is intended as a replacement to both fail2ban and epylog
|
2018-01-31 13:07:05 +01:00
|
|
|
|
# Copyright © 2017–2018 Y. Gablin
|
2017-12-16 18:59:33 +01:00
|
|
|
|
# Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing.
|
2018-02-26 18:55:45 +01:00
|
|
|
|
from enum import Enum, unique
|
2017-12-15 19:36:50 +01:00
|
|
|
|
from systemd import journal
|
|
|
|
|
|
2018-02-26 18:55:45 +01:00
|
|
|
|
@unique
|
|
|
|
|
class Level(Enum):
|
|
|
|
|
EMERG = 0 # System is unusable.
|
|
|
|
|
ALERT = 1 # Action must be taken immediately.
|
|
|
|
|
CRIT = 2 # Critical conditions, such as hard device errors.
|
|
|
|
|
ERR = 3 # Error conditions.
|
|
|
|
|
WARNING = 4 # Warning conditions.
|
|
|
|
|
NOTICE = 5 # Normal but significant conditions.
|
|
|
|
|
INFO = 6 # Informational messages.
|
|
|
|
|
DEBUG = 7
|
2017-12-15 19:36:50 +01:00
|
|
|
|
|
|
|
|
|
def log(level, string):
|
2018-02-26 18:55:45 +01:00
|
|
|
|
journal.send(string, PRIORITY = level.value)
|
2017-12-15 19:36:50 +01:00
|
|
|
|
|
|
|
|
|
def debug(string):
|
2018-02-26 18:55:45 +01:00
|
|
|
|
log(Level.DEBUG, string)
|
2017-12-15 19:36:50 +01:00
|
|
|
|
|
2018-02-11 13:17:48 +01:00
|
|
|
|
def notice(string):
|
2018-02-26 18:55:45 +01:00
|
|
|
|
log(Level.NOTICE, string)
|
2018-02-11 13:17:48 +01:00
|
|
|
|
|
2017-12-15 19:36:50 +01:00
|
|
|
|
def error(string):
|
2018-02-26 18:55:45 +01:00
|
|
|
|
log(Level.ERR, string)
|