Opened 19 years ago

Closed 19 years ago

Last modified 17 years ago

#55 closed defect (wontfix)

add a logger to django

Reported by: James Zhu Owned by: Adrian Holovaty
Component: Tools Version:
Severity: normal Keywords: log
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

insert the block into django.conf.settings file at line 32.

#python
a = me.SETTINGS_MODULE.split( '.' )
if 'settings' in a:
    idx = a.index( 'settings' )
    if idx > 0:
        projname = a[idx-1]
        projmod = __import__( projname , '', '', [''])
    else:
        projname = 'django'
        import django as projmod
    logdir = os.path.split( projmod.__file__ )[0] + os.sep + 'logs'
    if not os.access( logdir , os.W_OK ):
        raise 'Cannot write log file in dir: ' + logdir
    import logging
    logger = logging.getLogger( projname )
    hdlr = logging.FileHandler( logdir + os.sep + projname + '.log' )
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    hdlr.setFormatter(formatter)
    logger.addHandler( hdlr )
    logger.setLevel( logging.DEBUG )
    
    __builtins__['log'] = logger
    log.info( 'project logger start' )

make sure you have created 'logs' folder at your project or django src.
then you can use log object anywhere.

ATTENTION: NOT fully tested.

Change History (1)

comment:1 by Jacob, 19 years ago

Resolution: wontfix
Status: newclosed

I fail to see what this gains Django: if you'd like to use Python's logging, nothing prevents you, and hardcoding the log level and such into django.conf.settings is scary.

Note: See TracTickets for help on using tickets.
Back to Top