Last active
August 29, 2015 14:05
-
-
Save jorge-lavin/7d1cdeb4c800c8bddf89 to your computer and use it in GitHub Desktop.
typo at line 51
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
import os | |
import logging | |
import logging.config | |
''' | |
If you try to log to a non existing folder, this shows how an IOError exception is raised. The non existing folder may be /logs in current working directory. | |
IMPORTANT: This assumes a logging.ini configuration file for the logging exists with a log_file_path variable pointing at the file to be logged at. | |
The contents of logging.ini are: | |
[loggers] | |
keys=root | |
[handlers] | |
keys=console, execution | |
[formatters] | |
keys=dev | |
[handler_console] | |
class=StreamHandler | |
level=DEBUG | |
formatter=dev | |
args=(sys.stdout,) | |
[handler_execution] | |
class=handlers.RotatingFileHandler | |
level=DEBUG | |
formatter=dev | |
args=(r'%(log_file_path)s', 'a+', 'maxBytes=1024', 'backupCount=10',) | |
[formatter_dev] | |
format=%(asctime)s %(levelname)s : %(message)s - (%(module)s, line %(lineno)s) | |
datefmt='%m/%d/%y %H:%M:%S' | |
[logger_root] | |
level=DEBUG | |
handlers=console, execution | |
#TODO: A non file config version of this. | |
''' | |
log_ini_path = os.path.join(os.getcwd(), 'logging.ini') | |
options={'log_file_path': os.path.join(os.getcwd(), 'logs', 'app.log')} | |
try: | |
logging.config.fileConfig(log_ini_path, defaults=options) | |
except IOError as io_err: | |
print('Something happened during configuration of logging ...') | |
print(io_err) | |
print('Exiting ...') | |
exit(1) | |
logger = logging.getLogger() | |
logger.setLevel(logging.DEBUG) | |
logger.debug('Starting app....') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment