(→Log Levels) |
(→Log Levels) |
||
| Line 32: | Line 32: | ||
** Don't log too much. It makes reading the log difficult. Tracebacks should tell where we were when error happened. | ** Don't log too much. It makes reading the log difficult. Tracebacks should tell where we were when error happened. | ||
** Input parameters and sub commands (parameters, return values, stdout, stderr) are likely to be valuable information when debugging. | ** Input parameters and sub commands (parameters, return values, stdout, stderr) are likely to be valuable information when debugging. | ||
| + | ==== How to Log Exceptions ==== | ||
| + | |||
| + | Logging record objects have exc_info field and that should be used. No need to format or include the exception in the actual log message. This way it's easy to format every exception properly in the logging handlers or views. Current http logger views use this. | ||
| + | * In exception handlers it's enough to do | ||
| + | <pre> | ||
| + | log.exception("Catastrophic error") | ||
| + | </pre> | ||
| + | or | ||
| + | <pre> | ||
| + | log.debug("Catastrophic error", exc_info=True) | ||
| + | </pre> | ||
| + | If exception is received as an object, it can be logged properly like this: | ||
| + | <pre> | ||
| + | except Exception, err: | ||
| + | log.error("Catastrophic error", exc_info=err) | ||
| + | </pre> | ||
| + | or if it's the common (Type, Value, Traceback) tuple: | ||
| + | <pre> | ||
| + | def __exit__(self, exception_type, value, tb): | ||
| + | LOG.warning("Error in plugin", exc_info=(exception_type, value, tb)) | ||
| + | </pre> | ||
== Logs == | == Logs == | ||
Contents |
Different log levels are targeted for different user groups. See Typical OTS users and usage scenarios for more information.
These are available in the centralized testrun http log.
These logs are available in log files. Currently server debug log for each testrun is in /var/log/ots/. Conductor logs to ~/conductor.log in the worker machine. OTS worker process logs to /var/log/ots.log.
Logging record objects have exc_info field and that should be used. No need to format or include the exception in the actual log message. This way it's easy to format every exception properly in the logging handlers or views. Current http logger views use this.
log.exception("Catastrophic error")
or
log.debug("Catastrophic error", exc_info=True)
If exception is received as an object, it can be logged properly like this:
except Exception, err:
log.error("Catastrophic error", exc_info=err)
or if it's the common (Type, Value, Traceback) tuple:
def __exit__(self, exception_type, value, tb):
LOG.warning("Error in plugin", exc_info=(exception_type, value, tb))
There are a number of ways to view the OTS testrun:
The Main OTS log is written to
/var/log/ots
This is configurable by the 'logging.conf' file in the root directory
The Worker can be configured to log to a file specified by the "log_file" parameter in the Worker config file.
Writes to the <ahem> home directory
/path/to/home/conductor.log
If you are running OTS with Apache:
/var/log/apache2/error.log
In addition there is an http_logger.