def command(options): logger.debug( 'About to start %s ', options.name) # actually do the command processing here ... logger.info('Started the \' %s \' service.', options.name) 

and thus for stopping: 

(continued from previous page) 

# stop.py import logging logger=logging.getLogger(__name__ ) def command(options): n =len(options.names) if n ==1: plural='' services =' \' %s \' '%options.names[0] else : plural='s' services =','.join(' \' %s \' '%name for name in options.names) i =services.rfind(',') services =services[:i] +'and '+services[i +2:] logger.debug( 'About to stop %s ', services) # actually do the command processing here ... logger.info('Stopped the %s service %s .', services, plural) 

and similarly for restarting: 

# restart.py import logging logger=logging.getLogger(__name__ ) def command(options): n =len(options.names) if n ==1: plural='' services =' \' %s \' '%options.names[0] else : plural='s' services =','.join(' \' %s \' '%name for name in options.names) i =services.rfind(',') services =services[:i] +'and '+services[i +2:] logger.debug( 'About to restart %s ', services) # actually do the command processing here ... logger.info('Restarted the %s service %s .', services, plural) 

If we run this application with the default log level, we get output like this: 

$ python app.py start foo INFO start Started the 'foo' service. $ python app.py stop foo bar INFO stop Stopped the 'foo' and 'bar' services. $ python app.py restart foo bar baz INFO restart Restarted the 'foo', 'bar' and 'baz' services. 

The first word is the logging level, and the second word is the module or package name of the place where the event was logged. 

