Skip to main content

Register trainee teachers - Logging Documentation

Rails Semantic Logger

We use rails_semantic_logger instead of the default Rails logger because it provides enhanced logging capabilities. It solves several problems such as:

  • Structured Logging: Allows logs to be output in a structured format like JSON, making it easier to parse and analyze.
  • Multiple Output Formats: Supports different log output formats and destinations, providing flexibility in how logs are handled.
  • Performance: Offers better performance with asynchronous logging, reducing the impact on application throughput.
  • Log Filtering: Provides advanced filtering options to control which logs are recorded, helping to reduce noise and focus on important information.

Custom Log Formatter

The CustomLogFormatter class in app/lib/custom_log_formatter.rb customizes the log format. It extends SemanticLogger::Formatters::Json to provide a JSON formatted log output. This custom formatter adds job data, formats exceptions, and modifies the log message context.

Configuration in Production

In config/environments/production.rb, the logging is set up using the CustomLogFormatter. The configuration includes:

  • Disabling the file appender.
  • Setting the log format to use CustomLogFormatter.
  • Adding an appender for stdout with the custom formatter.

This configuration is shared across all environments except for the test and development environments.

Viewing Logs

Logs are viewed in Logit.io. Please replace the placeholders with the actual links:

Note: the two different GUID's used for Prod (production, productiondata) and Test (QA, staging, review apps)

Filebeat

Filebeat is a lightweight shipper for forwarding and centralizing log data. It is used as an intermediary between our application and Logit.io, ensuring that logs are efficiently shipped to the logging service.

References