Make WordPress Core

Opened 9 years ago

Last modified 20 months ago

#30934 assigned enhancement

Create a new API to standardize application logging

Reported by: ericlewis's profile ericlewis Owned by:
Milestone: Awaiting Review 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 (13)

#1 @ericlewis
9 years ago

  • Type changed from defect (bug) to enhancement

#2 @nacin
9 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.


9 years ago

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


9 years ago

#5 @ocean90
8 years ago

#37221 was marked as a duplicate.

#7 @ocean90
4 years ago

#50619 was marked as a duplicate.

#8 @ocean90
4 years ago

#50619 was marked as a duplicate.

#9 @thomasprice61
4 years 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 4 years ago by thomasprice61 (previous) (diff)

#10 @fpcorso
3 years ago

I think this is something that is much needed in core, especially as many major plugins are all creating their own system right now creating many redundancies that could be eliminated if core offered an extendable logging system.

My question would be who would have control over the logging level, structure, etc...: The site owner or the plugin/theme developer? For example, would the site owner set the logging structure using a constant and then all logs follow that, or would each developer set their own structure for log messages coming from their plugin or theme?

Similarly, is there one main site log or does each plugin/theme create their own log(s)? Does the site owner decide that or do the individual plugins decide that?

Last edited 3 years ago by fpcorso (previous) (diff)

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


3 years ago

#12 @pfefferle
22 months ago

While working on the ActivityPub, where I also need a PSR-3 logger for a generic lib, I wrote a simple wrapper that uses the error_log (like WP_DEBUG_LOG does). Maybe this can be used as a start. https://github.com/pfefferle/wp-psr-log

Last edited 22 months ago by pfefferle (previous) (diff)

#13 @desrosj
20 months ago

  • Milestone set to Awaiting Review
  • Owner nacin deleted

The sands of time continue to fall waiting for @nacin's proposal.

While I'd still like to see the notes from the community summit/draft proposal yet to be published, I'm removing the owner from this one in the hopes another contributor will come along with the noble desire to champion this one.

Note: See TracTickets for help on using tickets.