From Fedora Project Wiki
(Add an example of doing it in pure Python.)
Line 9: Line 9:
Most of our apps use the standard                                                                                                                                         
Most of our apps use the standard                                                                                                                                         
[http://docs.python.org/2/library/logging.handlers.html Python logging module],                                                                                           
[http://docs.python.org/2/library/logging.handlers.html Python logging module],                                                                                           
which usually ends up logging to '''/var/log/httpd/error_log''' on the local machine.                                                                                         
which usually ends up logging to '''/var/log/httpd/error_log''' on the app server.                                                                                         
                                                                                                                                                                            
                                                                                                                                                                            
To have your app logs shipped to our central logging server, you can configure                                                                                             
To have your app logs shipped to our central logging server, you can configure                                                                                             

Revision as of 20:24, 19 January 2013

Best Practices for Fedora Infrastructure Apps

Coding style

Centralized logging

Most of our apps use the standard Python logging module, which usually ends up logging to /var/log/httpd/error_log on the app server.

To have your app logs shipped to our central logging server, you can configure the SysLogHandler to do so.

For TurboGears-style config-file based logging setups, you can do something like the following:

[logging]                                                                                                                                                             
                                                                                                                                                                          
[[handlers]]                                                                                                                                                          
                                                                                                                                                                         
[[[syslog_out]]]                                                                                                                                                      
class='handlers.SysLogHandler'                                                                                                                                        
args="('/dev/log', handlers.SysLogHandler.LOG_LOCAL4,)"                                                                                                               
formatter='message_only'                                                                                                                                              
                                                                                                                                                                          
[[loggers]]                                                                                                                                                           
                                                                                                                                                                          
[[[bodhi]]]                                                                                                                                                           
level='DEBUG'                                                                                                                                                         
qualname='bodhi'                                                                                                                                                      
handlers=['syslog_out']                                                                                                                                               
propagate=0                                                                                                                                                           

Here is an example of doing it in pure Python:

import logging
import logging.handlers

syslogger = logging.getLogger('bodhi')
syslogger.setLevel(logging.WARN)
handler = logging.handlers.SysLogHandler(address='/dev/log', facility=logging.handlers.SysLogHandler.LOG_LOCAL4)
sysloggerr.addHandler(handler)

The app logs will then appear in /var/log/hosts/<HOST>/<YEAR>/<MONTH>/<DAY>/apps.log as well as the merged log /var/log/merged/apps.log.