473,327 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,327 developers and data experts.

Choosing log file destination in logging configuration file

Don't know if it's out there already but I've found a solution to this:
http://bytes.com/topic/python/answer...iguration-file

Expand|Select|Wrap|Line Numbers
  1. # logging.conf
  2. [loggers]
  3. keys=root
  4.  
  5. [handlers]
  6. keys=TimedRotatingFileHandler
  7.  
  8. [formatters]
  9. keys=simpleFormatter
  10.  
  11. [logger_root]
  12. level=DEBUG
  13. handlers=TimedRotatingFileHandler
  14.  
  15. [handler_TimedRotatingFileHandler]
  16. class=handlers.TimedRotatingFileHandler
  17. level=DEBUG
  18. formatter=simpleFormatter
  19. args=('C:\\log\\'+os.path.basename(sys.argv[0]).split('.')[0]+'.log', 'D', 15, 'backupCount=30')
  20.  
  21. [formatter_simpleFormatter]
  22. format=%(asctime)s %(message)s
  23. datefmt=%Y-%m-%d %H:%M:%S
  24.  
Expand|Select|Wrap|Line Numbers
  1. # main.py
  2. import logging, os
  3.  
  4. logging.config.fileConfig('C:\\log\\logging.conf')
  5. log = logging.getLogger()
  6. log.info('Started')
  7. #do stuff
  8. log.info('Finished')
  9.  
Nothing will be printed in the screen.

A file C:\log\main.log will be created and rotated every 15 days

The log will look like:
2011-07-04 12:18:16 Started
2011-07-04 12:18:19 Finished
I'm not sure about the logging levels and how to print in the screen when "log.info()" is called so i don't have to print that as well.

Cheers
Jul 4 '11 #1
0 4346

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Alexander Kienzle | last post by:
I'm new to Java programming. I'm developing a Servlet for tomcat which needs an external configuration file. With external I mean a file (in XML format) which is customizable and not contained in...
12
by: Rob Cranfill | last post by:
Hello, I've successfully coded Python to do what I want with a RotatingFileHandler, but am having trouble getting the same behavior via a config file. I wanted to create one log file each...
2
by: kathy | last post by:
What Application Configuration File is? And when/where/how to use it? Any documents on that? MSDN has somrthings scatter everywhere - hard to follow. thanks,
18
by: Conrad F | last post by:
Hello all, I am waiting for receipt of files in a directory. I use the FileSystemWatcher to detect when files arrive in said folder. I need to read the data from these files ASAP but the files...
4
by: Bob Rock | last post by:
Hello, I'd like to log to a file from an asp.net application but it seems that the user under which asp.net applications run has very limited permissions. Apart giving the user greater...
3
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type...
1
by: Matthew Wilson | last post by:
The python logging module is a beautiful masterpiece. I'm studying filters and the config-file approach. Is it possible to define a filter somehow and then refer to it in my config file? TIA ...
1
by: ashi1290 | last post by:
I am getting this error..... Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:120)...
3
by: guybenron | last post by:
Hey, I have a sort of petty-neurotic question, I'm kinda pedantic and like to keep my log directories clean, and this thing is bothering me to the point of actually posting a question (couldn't...
4
by: Matthew Wilson | last post by:
I'm working on a package that uses the standard library logging module along with a .cfg file. In my code, I use logging.config.fileConfig('/home/matt/mypackage/matt.cfg') to load in the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.