Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > custom handler does not write to log file

Reply
Thread Tools

custom handler does not write to log file

 
 
dj
Guest
Posts: n/a
 
      03-31-2009
It seems that you can create custom handlers and add them to the
logging.handlers namespace(http://mail.python.org/pipermail/python-
list/2008-May/493826.html.)
But for reasons beyond my understanding my log file (test.log) is not
written to.

#################### my handler class
################################################## #####
import logging.handlers


# create my handler class
class MyHandler(logging.handlers.RotatingFileHandler):
def __init__(self, filename):
logging.handlers.RotatingFileHandler.__init__(self , filename,

maxBytes=10485760, backupCount=5)


# Register handler in the "logging.handlers" namespace
logging.handlers.MyHandler = MyHandler

################ test app.py
################################################## ################
import logging
import logging.handlers

from myhandler import MyHandler

# log file path
LOG_FILE_PATH='H:/python_experiments/logging/test.log' # log file
path
#log file formatter
myformatter = logging.Formatter('%(asctime)s %(levelname)s %(filename)
s %(lineno)d %(message)s')

# setup a log instance for myHandler
logger2 = logging.getLogger('myLog2')
logger2.setLevel(logging.CRITICAL)
hdlr2 = logging.handlers.MyHandler(LOG_FILE_PATH)
hdlr2.setFormatter(myformatter)
hdlr2.setLevel(logging.CRITICAL)
logger2.addHandler(hdlr2)

# give it a try
print 'using myHandler'
logger2.debug('this is a test of myHandler')
print 'after logger using myHandler'

Thanks in advance for your help.
 
Reply With Quote
 
 
 
 
dj
Guest
Posts: n/a
 
      03-31-2009
On Mar 31, 1:13*pm, dj <(E-Mail Removed)> wrote:
> It seems that you can create custom handlers and add them to the
> logging.handlers namespace(http://mail.python.org/pipermail/python-
> list/2008-May/493826.html.)
> But for reasons beyond my understanding my log file (test.log) is not
> written to.
>
> #################### *my handler class
> ################################################## #####
> import logging.handlers
>
> # create my handler class
> class MyHandler(logging.handlers.RotatingFileHandler):
> * * def __init__(self, filename):
> * * * * logging.handlers.RotatingFileHandler.__init__(self , filename,
>
> maxBytes=10485760, backupCount=5)
>
> # Register handler in the "logging.handlers" namespace
> logging.handlers.MyHandler = MyHandler
>
> ################ *test app.py
> ################################################## ################
> import logging
> import logging.handlers
>
> from myhandler import MyHandler
>
> # log file path
> LOG_FILE_PATH='H:/python_experiments/logging/test.log' *# log file
> path
> #log file formatter
> myformatter = logging.Formatter('%(asctime)s %(levelname)s %(filename)
> s %(lineno)d %(message)s')
>
> # setup a log instance for myHandler
> logger2 = logging.getLogger('myLog2')
> logger2.setLevel(logging.CRITICAL)
> hdlr2 = logging.handlers.MyHandler(LOG_FILE_PATH)
> hdlr2.setFormatter(myformatter)
> hdlr2.setLevel(logging.CRITICAL)
> logger2.addHandler(hdlr2)
>
> # give it a try
> print 'using myHandler'
> logger2.debug('this is a test of myHandler')
> print 'after logger using myHandler'
>
> Thanks in advance for your help.


Kindly ingnore this message, turns out the problem was a
misunderstanding of the severity for the logging levels.
My bad. Thanks anyway .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom log handler and logging.config.fileConfig() Lowell Alleman Python 3 05-29-2008 05:28 PM
How does a handler render the request to another handler in the MVC of SPRING 2.0.1 framework? rayzyang@gmail.com Java 0 05-30-2007 11:28 AM
Encrypt custom web.config section / cannot load custom handler? MichaelS ASP .Net Security 0 11-22-2006 04:11 PM
Write to error log using redirect:write Petterson Mikael XML 1 09-11-2006 12:06 PM
ASP Problem: "IIS log failed to write entry" in Event Log cherryparadise001@gmail.com ASP General 0 05-26-2006 01:52 AM



Advertisments