Django

Code

Ticket #55 (closed: wontfix)

Opened 4 years ago

Last modified 2 years ago

add a logger to django

Reported by: james Assigned to: adrian
Milestone: Component: Tools
Version: Keywords: log
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.

Attachments

Change History

07/20/05 16:49:50 changed by jacob

  • status changed from new to closed.
  • resolution set to wontfix.

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.


Add/Change #55 (add a logger to django)




Change Properties
Action