Commit bd7bd8eb authored by Daniel STAN's avatar Daniel STAN

secrets_new: utilisation d'un vrai logger

Pour éviter de concurrence le syslog perso de l'application qui importe
secrets_new (c'est ce qui arrive avec freeradius)
parent afed5881
......@@ -25,14 +25,26 @@ Recuperation des secrets depuis /etc/crans/secrets.
import sys
import os
from syslog import syslog, openlog
import logging
import logging.handlers
import getpass
# Initialisation d'un logger pour faire des stats etc
# pour l'instant, on centralise tout sur thot en mode debug
logger = logging.getLogger('secrets_new')
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(name)s: [%(levelname)s] %(message)s')
handler = logging.handlers.SysLogHandler(address = '/dev/log')
try:
handler.addFormatter(formatter)
except AttributeError:
handler.formatter = formatter
logger.addHandler(handler)
def get(secret):
""" Recupere un secret. """
openlog('secrets_new')
""" Récupère un secret. """
prog = os.path.basename(getattr(sys, 'argv', ['undefined'])[0])
syslog('%s (in %s) asked for %s' % (getpass.getuser(), prog, secret))
logger.debug('%s (in %s) asked for %s' % (getpass.getuser(), prog, secret))
try:
f = open("/etc/crans/secrets/" + secret)
result = f.read().strip()
......@@ -45,5 +57,5 @@ def get(secret):
sys.path.pop()
return getattr(module, secret)
except:
syslog('...and that failed.')
logger.critical('...and that failed.')
raise Exception("Impossible d'acceder au secret %s!" % secret)
Markdown is supported
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