Commit 84f389db authored by Pierre-Elliott Bécue's avatar Pierre-Elliott Bécue

[clogger] Une petite lib pour logger dans /var/log/clogger facilement.

 * Livrée avec son utilitaire pour créer le dossier et lui mettre les
 bons droits.
parent 19cfe782
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Basic logger, storing data in /var/log/clogger/*.log
# Author : Pierre-Elliott Bécue <becue@crans.org>
# License : GPLv3
# Date : 27/04/2014
import logging
class CLogger(logging.Logger):
"""
Crans logger
"""
def __init__(self, loggerName, level):
"""
Initialise le logger
"""
super(CLogger, self).__init__(loggerName)
# Creates FileHandler
self.fh = logging.FileHandler("/var/log/clogger/%s.log" % (loggerName,))
if level == "debug":
self.fhlevel = logging.DEBUG
elif level == "info":
self.fhlevel = logging.INFO
elif level == "warning":
self.fhlevel = logging.WARNING
else:
self.fhlevel = logging.CRITICAL
self.fh.setLevel(self.fhlevel)
# Creates formatter
self.formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Adds formatter to FileHandler
self.fh.setFormatter(self.formatter)
# Adds FileHandler to Handlers
self.addHandler(self.fh)
#!/bin/bash
sudo mkdir /var/log/clogger
sudo chown respbats:adm /var/log/clogger
sudo chmod g+ws /var/log/clogger
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