Skip to main content

Frappe Logging API in Frappe Framework v15

What Is the Frappe Logging API?

The Frappe Logging API in Frappe Framework v15 provides structured mechanisms to record application errors, warnings, and debug information on the server. It helps developers diagnose issues, monitor system behavior, and ensure application stability across ERPNext deployments.

Logging in Frappe is primarily handled at the server level using built-in utility functions.

Who Should Use the Frappe Logging API?

Target Audience

  • ERPNext Developers
  • Frappe Framework Backend Developers
  • System Administrators
  • ERP Implementation Consultants

Technical Prerequisites

  • Frappe Framework v15
  • Python (backend development)
  • Understanding of server-side execution flow

How Does Logging Work in Frappe v15?

Frappe records logs at multiple levels, including:

  • Application errors
  • Tracebacks and exceptions
  • System messages

Logs are written to the database or log files depending on the logging method used.

Core Logging Utilities

  • frappe.log_error
  • Python logging module (used internally)

Module: Database / Utilities
Source Reference (v15): frappe/utils/error.py

How to Log Errors Using frappe.log_error?

Basic Error Logging Example

import frappe
try:
result = 10 / 0
except Exception:
frappe.log_error(
title="Division Error",
message=frappe.get_traceback()
)

What this does:

Captures the full traceback and stores it in the Error Log DocType, making it visible in the ERPNext Desk.

Where Are Logged Errors Stored?

Errors logged using frappe.log_error are stored in the Error Log DocType.
Key Fields

  • Error Title
  • Traceback
  • Method
  • Reference DocType
  • Reference Name

These logs can be accessed from Settings → Error Log in the Desk.

How to Log Custom Messages?

frappe.log_error(
message="Unexpected condition encountered in stock validation",
title="Stock Validation Warning"
)

This approach is useful for capturing business-rule violations or unexpected conditions without raising exceptions.

How to Log Errors Inside Whitelisted Methods?

@frappe.whitelist()
def process_data():
try:
# custom logic
pass
except Exception:
frappe.log_error(
frappe.get_traceback(),
"Process Data Failure"
)
frappe.throw("Processing failed. Please contact administrator.")

This ensures errors are logged while maintaining user-friendly messages.

Common ERPNext Use Cases for Logging

Industry Relevance

  • Manufacturing: Production validation failures
  • Finance: Posting or reconciliation errors
  • Sales: Pricing rule misconfigurations
  • HR: Payroll computation issues

Logging enables faster troubleshooting and system reliability.

Best Practices for Logging in Frappe v15

  • Log full tracebacks using frappe.get_traceback()
  • Use meaningful titles for easier identification
  • Avoid logging sensitive data
  • Log only actionable or critical events
  • Combine logging with exception handling

Troubleshooting Common Logging Issues

Error Not Appearing in Error Log

  • Ensure frappe.log_error is executed
  • Confirm no silent exception handling
  • Verify database write permissions

Excessive Logs

  • Avoid logging inside loops
  • Log only unexpected conditions

Advanced Logging Considerations

Logging vs Throwing Exceptions

Action Purpose
frappe.log_error Records error for administrators
frappe.throw Stops execution and notifies user

Use both together when appropriate.

Integration Patterns

The Logging API integrates with:

  • Server Calls (frappe.call)
  • Background Jobs
  • Scheduled Tasks
  • Custom REST APIs

It plays a key role in monitoring complex ERPNext workflows.

Official References

📘 Logging API Docs (v15):

https://docs.frappe.io/framework/user/en/api/logging

💻 Frappe GitHub (v15):

https://github.com/frappe/frappe/tree/version-15

Rating: 5 / 5 (4 votes)