473,624 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Choosing log file destination in logging configuration file

1 New Member
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 4366

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

Similar topics

2
8673
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 my package. I don't want to hardcode any path and I would like to be independent of the application server (tomcat, websphere,...). Until now, I put the file in my package and open it using obj.getClass.getResourceAsStream but when I put my...
12
12708
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 time I run my app, with up to 10 files kept from the last invocations. This was accomplished with self._logger = logging.getLogger('PDGUI')
2
3452
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
20171
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 are created and detected before writing completes and so I cannot read them until the file handle used in their creation has been released. This would be easy to get around with file renaming or other file locking mechanisms which I could use...
4
1359
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 permissions, is there any other solution to allow logging to file system??? Also I'd like to write to the bin or root asp.net application folder, how do I get this folder dynamically from the application itself???
3
12048
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 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (machine.config) ---> System.Security.SecurityException: Request for the permission of type
1
2097
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 Matt
1
4055
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) at com.author.hbn.HibernateUtil.<clinit>(HibernateUtil.java:12) at com.author.app.Abhi.main(Abhi.java:13) Configuration file looks like this <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration SYSTEM...
3
2220
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 find any post about this..). My application has two types of components: daemons and regular ones that are run every on crontab. Because the log structure is very similar, I want both to use the same logging configuration file.
4
2361
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 logging config file. However, it seems really obvious to me that this won't work when I share this package with others.
0
8236
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8173
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8679
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8475
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.