modified the logging to comply with what is on the docs.python.org page on the logging library and how it should be used

This commit is contained in:
Stephen McQuay 2011-03-22 11:10:19 -06:00
parent 2c07c3ba45
commit 05d1b962fc
5 changed files with 25 additions and 32 deletions

View File

@ -0,0 +1,18 @@
import logging
import logging.handlers
config = {
'filename': '/tmp/interpolatoryawesome.log',
'level': logging.DEBUG,
'size' : 1024000,
'backupCount': 10,
}
logger = logging.getLogger('interp')
logger.setLevel(config['level'])
my_format = logging.Formatter('%(asctime)s %(levelname)s (%(process)d) %(filename)s %(funcName)s:%(lineno)d %(message)s')
handler = logging.handlers.RotatingFileHandler(
config['filename'], maxBytes = config['size'] * 1024, backupCount = config['backupCount'])
handler.setFormatter(my_format)
logger.addHandler(handler)

View File

@ -3,7 +3,9 @@ import sys
import numpy as np import numpy as np
import itertools import itertools
from interp.tools import log
import logging
log = logging.getLogger("interp")
def get_phis(X, R): def get_phis(X, R):
""" """

View File

@ -9,8 +9,8 @@ from scipy.spatial import KDTree
from interp.baker import run_baker from interp.baker import run_baker
import interp.grid.simplex import interp.grid.simplex
#TODO: do logging right import logging
from interp.tools import log log = logging.getLogger("interp")
class grid(object): class grid(object):
def __init__(self, verts = None, q = None): def __init__(self, verts = None, q = None):

View File

@ -1,5 +1,4 @@
from interp.baker import get_phis from interp.baker import get_phis
from interp.tools import log
TOL = 1e-8 TOL = 1e-8

View File

@ -1,36 +1,10 @@
import os import os
import logging
import logging.handlers
import inspect import inspect
import numpy as np import numpy as np
import logging
def get_logger(filename, level = logging.DEBUG, logger_name = 'interp', size = 2048, backupCount = 10): log = logging.getLogger("interp")
"""
This is a simple wrapper around a few sane
defaults using Python's logging functionality.
An explaination of the optional parameters:
filename : the filename
level : one of either debug, info, warn, or error
logger_name : if one needs multiple logfiles, one must name them.
size : the size in bytes of the logfile before roll (defaults to 2MB)
backupCount : number of rolled logs to keep around (defaults to 10)
"""
logger = logging.getLogger(logger_name)
logger.setLevel(level)
my_format = logging.Formatter('%(asctime)s %(levelname)s (%(process)d) %(filename)s %(funcName)s:%(lineno)d %(message)s')
handler = logging.handlers.RotatingFileHandler(
filename, maxBytes = size * 1024, backupCount = backupCount)
handler.setFormatter(my_format)
logger.addHandler(handler)
return logger
log = get_logger(filename = '/tmp/interp.log', level = logging.INFO, size = 10240)
def rms(errors): def rms(errors):
""" """