You're viewing all posts tagged with example
Great setup example for Nginx + FastCGI + Mercurial hgwebdir
It also uses fabfile for automation of start / restart process.
http://streamhacker.com/2009/07/28/how-to-deploy-hgwebdir-fcgi-behind-nginx-with-fab/
Comments:
45
Python logging example and helper
When trying to find simple example on how to use Python logging module for writing logs to file, I became frustrated, as there are only a few useful examples. Here’s one that really works and covers most of use cases: see it on mechanicalcat.net.
And here’s simple helper to open log file, based on that example:
import re
import logging
def openlog(filename, logger_name=None, level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s'):
if not logger_name:
logger_name = filename[filename.rfind('/')+1:]
logger = logging.getLogger(logger_name)
handler = logging.FileHandler(filename)
formatter = logging.Formatter(format)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(level)
return logger
So, you can simply use this helper like this:
logger = openlog('/var/log/just_a_test.log')
logger.debug("hello, i'm debug message!")
Actually, basic examples are provided in docs. I missed them first time, because reference seems to be complicated at start point.
Comments:
45