WordPress.org

Make WordPress Core

Opened 6 years ago

Last modified 3 weeks ago

#30934 assigned enhancement

Create a new API to standardize application logging

Reported by: ericlewis Owned by: nacin
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

There are moments in WordPress' execution that it would be helpful to have application debug logging.

One that has bitten me hard is multisite redirects when the current blog can't be initialized properly. It would be great to be able to look at a log somewhere that tells me [error] No site found for ericandrewlewis.com /srv/www/wordpress/wp-includes/ms-settings.php:162.

This is just one instance, but opens up a discussion of a consistent API that we can use, both internal to core and in plugins / themes for application logs.

#28319 was a similar request (Add hook to WP_Error for logging and report purposes), but missed the point that WP_Error is a standardized error return value from a function, and not necessarily an application error. However, from that ticket dd32 proposed creating a PSR-3 inspired API for logging errors. Let's consider this.

Change History (9)

#1 @ericlewis
6 years ago

  • Type changed from defect (bug) to enhancement

#2 @nacin
6 years ago

  • Owner set to nacin
  • Status changed from new to assigned

I proposed something along these lines at the community summit and I'm working on a more complete proposal for this. Give me a few days.

This ticket was mentioned in Slack in #core by eric. View the logs.


6 years ago

This ticket was mentioned in Slack in #core by eric. View the logs.


6 years ago

#5 @ocean90
4 years ago

#37221 was marked as a duplicate.

#7 @ocean90
4 weeks ago

#50619 was marked as a duplicate.

#8 @ocean90
4 weeks ago

#50619 was marked as a duplicate.

#9 @thomasprice61
4 weeks ago

Adding my voice to this ...

WordPress currently has:

  • debugging by including in wp-config.php: WP_DEBUG, WP_DEBUG_LOG, WP_DEBUG_DISPLAY which will generate a log file, display on screen, etc
  • access to the PHP function error_log() to record information in WP_DEBUG
  • a folder wp-content/logs/ but there are no guidelines if or how it should be used.

Logging Best Practice generally includes determining the:

  • Purpose and scope of what should be logged: for debugging, for security, for business rules such as exception handling, etc.
  • Log structure and characteristics, such as log levels (critical, error, warning, information, debug), etc.
  • Output of logging such as presentation, alerting, processes, etc
  • Management of log information, resources, tools and processes

Logging Framework:

  • WordPress currently only provides basic logging for a developer. There is a large gap between this and Best Practice.
  • Plugins can close this gap for those needing comprehensive logging capabilities
  • But ... WordPress could deliver a great logging framework with little effort

Proposed Enhancement:

  • Develop a core function wp_log()
  • Characteristics should allow a developer to configure:
    • log destinations (error_log(), screen and file. Maybe suggest wp-content/logs/plugin-name/log-file-name)
    • log structure (example: [YYYYMMDD hh:mm:ss][level] message)
  • It could also include hooks so 3rd parties can further enhance logging (example: allow a 3rd party to configure rolling log files, log to external log sinks, etc)

Suggested approach:

Last edited 3 weeks ago by thomasprice61 (previous) (diff)
Note: See TracTickets for help on using tickets.