Comprehensive Guide to Utilizing the Logging Feature in Empress for Developers

Introduction

In a software development scenario, debugging is a crucial part of the process. It helps identify, diagnose, and repair issues that might affect the functionality of the application. Empress has made this process easier by introducing a Logging Feature that improves the debugging experience.

The Logging Feature works on two main categories based on accessibility:

  1. Desk Logs: These logs are stored in your site database and can be accessed and queried as Documents.
  2. Server Logs: These logs are stored in files managed by a Log Rotation system.

Desk Logs

Desk Logs are accessible via the Desk UI. They are mainly used to track operational events. However, their APIs can be utilized to monitor any event from your Empress apps.

Several logs in the Core module include:

  • Access Log
  • Activity Log
  • Error Log
  • Scheduled Job Log

These logs can be checked directly on your site for more detailed information.

Server Logs

Server Logs consist of lower-level, transactional data compared to those accessible from the Desk. From Version 13, logs are available at the site level too.

Server logs are typically found under:

  • ./logs
  • ./sites/{site}/logs

Currently, only frappe.web.log and scheduler.log are logged at the site and bench level.

Some of the most useful files at the bench level could be:

  • bench.log
  • scheduler.log
  • worker.log

These logs provide insights into the bench commands executed and the status of jobs run by your Scheduler or Background Jobs.

To enable Empress Web Logging on your site, update the site config with enable_frappe_logger: true

Error Snapshots

In addition to these logs, Empress maintains error snapshots for your sites for HTTP response codes from 500 and above. This is implemented to provide more context for failures in case of server errors.

For instance, a desk action failing with HTTP status code 500 would add a corresponding log in the ./sites/{site}/frappe.log file.

These error snapshots are periodically synced with the site’s database and are available via the desk with records added under the DocType Error Snapshot. They are maintained for a month from creation before each record is deleted.

To disable this feature for your site, update the site config with disable_error_snapshot: true

Processes

Server Logs may be generated by the bench CLI, your process manager, or the Empress application directly. The process managers handle getting all the moving parts up and running for your Empress environment and directing output and error streams to your log files.

For more detailed logging, you can use the Monitor to log more information about all the requests to your site.

Maintenance

Log files may get large over time if unchecked. To know which files to track, checkout the supervisor.conf or Procfile on your bench, depending on whether you’re running a production or development instance.

Auto Cleanup of Old Logs

Most logging doctypes in Empress support configurable retention period with sane defaults via the Log Settings DocType.

You can register your custom logging doctype with log settings by adding a single static method to your doctype controller. Custom logging doctypes that implement this method will automatically show up in Log Settings.

Conclusion

The Logging Feature in Empress is a powerful tool that allows developers to effectively monitor and debug their applications. Not only does it provide detailed information about operational events, but it also maintains error snapshots for better context and diagnosis. With the proper use of this feature, developers can significantly improve the debugging experience and contribute to the overall development and customization of business solutions in Empress.