safe.common.custom_logging module

InaSAFE Disaster risk assessment tool developed by AusAid -
Logging related code.

Contact : ole.moller.nielsen@gmail.com

Note

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

class safe.common.custom_logging.QgsLogHandler(level=0)[source]

Bases: logging.Handler

A logging handler that will log messages to the QGIS logging console.

emit(record)[source]

Try to log the message to QGIS if available, otherwise do nothing.

Parameters:record – logging record containing whatever info needs to be logged.
safe.common.custom_logging.add_logging_handler_once(logger, handler)[source]

A helper to add a handler to a logger, ensuring there are no duplicates.

Parameters:
  • logger (logging.logger) – Logger that should have a handler added.
  • handler (logging.Handler) – Handler instance to be added. It will not be added if an instance of that Handler subclass already exists.
Returns:

True if the logging handler was added, otherwise False.

Return type:

bool

safe.common.custom_logging.setup_logger(logger_name, log_file=None, sentry_url=None)[source]

Run once when the module is loaded and enable logging.

Parameters:

Borrowed heavily from this: http://docs.python.org/howto/logging-cookbook.html

Now to log a message do:

LOGGER.debug('Some debug message')

Note

The file logs are written to the inasafe user tmp dir e.g.: /tmp/inasafe/23-08-2012/timlinux/logs/inasafe.log