Created
January 2, 2013 18:19
-
-
Save gmr/4436632 to your computer and use it in GitHub Desktop.
Rewrite Cobbler's clogger.py module to be a wrapper for the Python stdlib logging.Logger class while keeping almost the same behavior. Add in a format that provides more traceback information. Note line #39 should be super(Logger, self).__init__(__name__, level) but I was getting a weird exception I did not want to dig into.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Python standard logging doesn't super-intelligent and won't expose filehandles, | |
which we want. So we're not using it. | |
Copyright 2009, Red Hat, Inc and Others | |
Michael DeHaan <michael.dehaan AT gmail> | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation; either version 2 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
02110-1301 USA | |
""" | |
import logging | |
ERROR = logging.ERROR | |
WARNING = logging.WARNING | |
DEBUG = logging.DEBUG | |
INFO = logging.INFO | |
FORMATTER = logging.Formatter('%(levelname) -10s %(asctime)s %(process)-6d ' | |
'%(name) -15s %(funcName) -15s %(lineno) -5d: ' | |
'%(message)s') | |
LOGGER = logging.getLogger(__name__) | |
class Logger(logging.Logger): | |
def __init__(self, file_path='/var/log/cobbler/cobbler.log', | |
level=logging.DEBUG): | |
logging.Logger.__init__(self, __name__, level) | |
self._builtin_handler = logging.FileHandler(file_path) | |
self._builtin_handler.setFormatter(FORMATTER) | |
self.addHandler(self._builtin_handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment