From Fedora Project Wiki
(use the full_content formatter)
(translations, web frameworks)
Line 1: Line 1:
= Best Practices for Fedora Infrastructure Apps =                                                                                                                                                                                                                                                                                                          
== Best Practices for Fedora Infrastructure Apps ==
                                                                                                                                                                         
 
== Coding style ==                                                                                                                                                            
=== Coding style ===                                                                                                                                                                   
                                                                                                                                                                   
* Python code should be [http://www.python.org/dev/peps/pep-0008/ PEP8 compliant]  
* Python code should be [http://www.python.org/dev/peps/pep-0008/ PEP8 compliant]                                                                                        
                                                                                                                                                                       
                                                                                                                                                                         
=== Centralized logging ===
== Centralized logging ==                                                                                                                                                    
                                                                                                                                                                            
                                                                                                                                                                            
Most of our apps use the standard                                                                                                                                         
Most of our apps use the standard                                                                                                                                         
Line 50: Line 49:
'''/var/log/hosts/<HOST>/<YEAR>/<MONTH>/<DAY>/apps.log''' as well as the merged log                                                                                             
'''/var/log/hosts/<HOST>/<YEAR>/<MONTH>/<DAY>/apps.log''' as well as the merged log                                                                                             
'''/var/log/merged/apps.log''' on our central rsyslog server.
'''/var/log/merged/apps.log''' on our central rsyslog server.
=== Translations ===
Use transifex to manage translations and add the projects to the Fedora Project Team so the Fedora i18n team can translate.
Do not mark Exception messages for translation.  We want those to remain untranslated for several reasons:
# It's easier to do a web search for the exceptions if the messages aren't translated.
# Translators don't know what all the technical information in exception messages are so the translations aren't always accurate.
# The exception messages aren't intended for end users -- they're to help with debugging or other coders.  So it's not very useful to translate them.
=== Web Frameworks ===
Use one of Flask, Pyramid, or TurboGears2.  Limiting the number of web frameworks we're responsible for will greatly help with our long term maintenance burden.

Revision as of 01:16, 23 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 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='full_content'                                                                                                                                              
                                                                                                                                                                          
[[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.DEBUG)
handler = logging.handlers.SysLogHandler(address='/dev/log', facility=logging.handlers.SysLogHandler.LOG_LOCAL4)
syslogger.addHandler(handler)
syslogger.info('Hello SysLog!')

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 on our central rsyslog server.

Translations

Use transifex to manage translations and add the projects to the Fedora Project Team so the Fedora i18n team can translate.

Do not mark Exception messages for translation. We want those to remain untranslated for several reasons:

  1. It's easier to do a web search for the exceptions if the messages aren't translated.
  2. Translators don't know what all the technical information in exception messages are so the translations aren't always accurate.
  3. The exception messages aren't intended for end users -- they're to help with debugging or other coders. So it's not very useful to translate them.

Web Frameworks

Use one of Flask, Pyramid, or TurboGears2. Limiting the number of web frameworks we're responsible for will greatly help with our long term maintenance burden.