I  usually use the python logging facility for doing logging in django
Any way the below is code i write
------------------
i hope you can figure out what is happening here

1. Prepare logging conf file and name it  as logging.conf and put
under project directory

   Here goes the typicall contents
   ------------------------------------------------

   [loggers]
keys=root,scoremore,scoremore.sampleapp     #loggers for different
apps

[handlers]
keys=consoleHandler,rfileHandler

[formatters]
keys=simpleFormatter

[logger_scoremore.sampleapp]
level=DEBUG
handlers=consoleHandler,rfileHandler
qualname=scoremore.sampleapp
propagate=0

[logger_scoremore]
level=DEBUG
handlers=consoleHandler,rfileHandler
qualname=scoremore
propagate=0

[logger_root]
level=DEBUG
handlers=consoleHandler,rfileHandler

[handler_consoleHandler]  #display on console all message which are >=
DEBUG
class=StreamHandler
level=DEBUG  #you need define as per your needs
formatter=simpleFormatter
args=(sys.stdout,)

[handler_rfileHandler]  #also put on file all messages which are
greater that  >= DEBUG
class=handlers.RotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=(%(log_path)s,'a',5000000,5)  # we will pass the file path here
to which log messages to appear

[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=


---------------------------------
2. put down the following in settings.py
===============================
# initialization of logging module

#LOG_FILE_PATH in django
LOG_FILE_PATH = "\""+os.path.join(os.path.dirname(os.path.normpath
(__file__)),"logs.txt")+"\""
#LOG FILE NAME In django
LOG_FILE_NAME = os.path.join(os.path.dirname(os.path.normpath
(__file__)),'logging.conf')

#loading the logging configuration
logging.config.fileConfig(LOG_FILE_NAME,defaults=dict
(log_path=LOG_FILE_PATH))


3.so you have defined the configuration and also initialized the
logging (means telling  various loggers ,handlers,formatters)
   whenever you want use logging in any view or models do the below
 -------------------

import logging
import logging.config

mlogger = logging.getLogger(__name__) #name is module name it chooses
the  logger which contains name as prefix if none it chooses root


#now use this mlogger.debug to print message at debug level and
mlogger.info to print messages at info level
mlogger.debug("completed the question paper at present reviewing it")


Hope the above is clear for you to start...................

--rama vadakattu





.


























On Jun 18, 11:20 pm, "eric.frederich" <eric.freder...@gmail.com>
wrote:
> I need some advice on using the python logging module with django-
> logging.
>
> I have djangologging installed and working.  I read the documentation
> and am trying to figure out how I can best take advantage of the built
> in logging module.  The djangologging docs mention adding handlers and
> other things.  I could not find any practical examples of using this
> on a django site.
>
> I'm not sure what I want yet... either one big log for my entire
> django site or separate logs per application.  I could go either way,
> although if some of my apps talk to each other it might be nice to
> have a single log.
>
> Anyway, I am to the point now where I am sending emails where
> appropriate to users and admins.  What I would like now is to create
> logs for things that are important to log but not necessarily
> important enough to fill someone's inbox with.
>
> I was having trouble getting through Python's logging module
> documentation.  I am largely confused.  It mentions hierarchy and
> inheritance and root loggers and such.  How am I supposed to use this
> module?  Do I just run logging.info() and logging.warn() and have my
> own logger inherit from the root, or do I call info or warn on my own
> instance of logger?
>
> In the end I just want to be able to have a simple line here and there
> within my views where I can output to a log file.
>
> Could give me some help to get up and running?
>
> Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to