Skip to content

Logging

Pykour provides functionality for outputting logs. Logs are used for debugging, error tracking, and monitoring the operation of the application.

Access logs

Access logs are used to record information about clients that access the application and are automatically generated by Pykour.

The access log records the following information:

  • Date and time when the access log was recorded
  • An ID to uniquely identify the request (Request ID)
  • Client’s IP address/port number
  • HTTP method of the request
  • URL of the request
  • HTTP status code/version of the request
  • HTTP status code
  • Response body size (in bytes)
  • Request processing time (in seconds)
ACCESS [2024-08-20T12:34:56.123+0900] [d92eb65c-0b76-445e-82aa-d980759ea42e] 127.0.0.1:60933 - - GET / HTTP/1.1 200 OK 28 0.123

Log Output Settings

Log output settings are configured in the configuration file.

pykour:
  logging:
    level: INFO, WARN, ERROR, DEBUG

In pykour.logging.level, you can enumerate the log levels to be output.

The following log levels are available:

  • INFO: Outputs general information.
  • WARN: Outputs warning information.
  • ERROR: Outputs error information.
  • DEBUG: Outputs debugging information.

Log output

Logs are output using the pykour.logging module. The following example demonstrates how to output logs.

from pykour import Pykour, logging

app = Pykour()

@app.route('/')
def index():
    logging.write_info_log('Hello, World!')
    return 'Hello, World!'

In the example above, the write_info_log function is used to output a log. The type of log is specified by the argument of the write_info_log function.

The following log types are available:

  • write_info_log: Outputs general information.
  • write_warn_log: Outputs warning information.
  • write_error_log: Outputs error information.
  • write_debug_log: Outputs debugging information.