Created
August 26, 2014 18:24
-
-
Save mteodoro/27d488febe1e2430c237 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import logging | |
import logging.handlers | |
import optparse | |
def init_logger(opts): | |
level = logging.INFO | |
handler = logging.StreamHandler() | |
#handler = logging.handlers.SysLogHandler(address='/dev/log') | |
if opts.debug: | |
level = logging.DEBUG | |
handler = logging.StreamHandler() | |
root = logging.getLogger() | |
root.setLevel(level) | |
root.addHandler(handler) | |
def parse_args(argv): | |
if argv is None: | |
argv = sys.argv[1:] | |
p = optparse.OptionParser() | |
#p.usage = '%prog [options] <arg>+' | |
p.add_option('-d', '--debug', action='store_true', | |
default=False, help="debug mode") | |
opts, args = p.parse_args(argv) | |
#sanity check | |
return opts, args | |
def main(argv=None): | |
global opts | |
opts, args = parse_args(argv) | |
init_logger(opts) | |
logging.debug(opts) | |
logging.debug(args) | |
logging.info('hello world') | |
if __name__ == '__main__': | |
rval = main() | |
logging.shutdown() | |
sys.exit(rval) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment