PSR3-compatible generic logging facility

Sim

Well-known member
I think a generic activity log (with admin UI) which implements the PSR-3 logging interface would be very useful as part of the core.

Add-ons can then log activity and errors there for the administrators to monitor.

Add-ons can choose which log level to send - for example informational updates (eg "X number of emails sent by this cron entry") or debugging ("output from this SOAP call").

The logging facility would implement the standard PSR-3 log levels (emergency, alert, critical, error, warning, notice, info, debug) and the UI would allow filtering log messages by date, PSR-3 log level and/or add-on id.

Also, the administrator would be able to set a minimum log level to actually get stored (eg only warning and above), so that spurious debug and info logs don't fill up the database on production servers.

Add-on developers could also potentially extend the capabilities of this core logging facility to send log information to external application monitoring systems (eg New Relic) or even just to notification systems (HipChat, Slack, etc).

Implementing a PSR-3 interface would also allow us to wire external packages (eg payment gateways, integration libraries, etc) to the logging system such that any log messages they send will automatically end up in the XenForo log - even if those packages were not built with XenForo in mind.
 
Upvote 12
As a further suggestion - pulling in the excellent Monolog logging library (MIT licensed) to be part of the XenForo core would provide most of the base functionality required here - including a standard interface, the ability to wire other packages in, multiple input channels, multiple destination handlers - including the ability to extend the built in functionality with custom handlers.

The base implementation would log directly to the database, while add-on developers could easily extend the functionality to provide additional handlers for other logging destinations.

For example, I'd love the ability to be able to redirect (or supplement) server error logs to an external monitoring application for direct alerting (eg a HipChat message or an SMS message) - Monolog as part of the core would allow for this without that much additional work by an add-on developer.
 
My corresponding suggestion from xf2demo site (https://xf2demo.xenforo.com/threads/expose-psr-3-logger.2609/):

We have the psr/log library shipping with XF2 courtesy of some of the other libraries that are used, but it is not used in any way by the XF framework that I can see, nor is it exposed for addon developers to take advantage of.

It would be great if we had a log service exposed (preferrably with a PSR-3 LoggerInterface implementation) that we can utilise from within our addons.

Opportunities this then opens up:
  1. developers could use standard PSR-3 logging interface to insert debug code into their addons without needing to worry about exactly where those logs will go (that's an administration decision)
  2. XF core could implement a PSR-3 logger implementation for logging to the database (as per this suggestion: https://xf2demo.xenforo.com/threads/development-debug-log-ui.2608/)
  3. XF core could make it easy for other PSR-3 logging implementations to be wired in and configured (ie for external application logging services such as Loggly)
  4. you could just ship Monolog with XF core - that would give us a heap of flexibility - Monolog already has the ability to send to a lot of 3rd party logging services
Monolog isn't strictly required - provided that we have the PSR-3 interface available, developers can just log things (using the PSR-3 severity levels) and leave the details of what actually gets stored in the logs - and exactly where those logs are ... to the administrator.

For production use, it would be fantastic to have other core XF logs (server log, moderator log, etc) exposed to an external logging application which can then send alerts when things go wrong. A PSR-3 logging interface which we can wire to Monolog or similar would facilitate that!
 
ACK. Though I fear that it is too late already to add this to XF 2.0, but would be awesome if it could be done for a future version.
 
This wouldn't be a large change for XF2, and I really want it. I'm tired of having to hack in the hostname to be included when logging an error. When dealing with multiple front-end webservers, knowing which server triggered the error is critical.
 
This wouldn't be a large change for XF2, and I really want it. I'm tired of having to hack in the hostname to be included when logging an error. When dealing with multiple front-end webservers, knowing which server triggered the error is critical.

... and while it's easy enough to write an addon to do this, it would then become a dependency on every other addon which wants to output logging information, so much better as part of the core.

There are some good external and SaaS log management systems available now which can trigger alerts when problems are detected - quite important for a large and busy site.
 
This is a kinda old thread, but not having a proper logging facility is a real PITA.

Even just smth. super simple like
PHP:
$container['logger'] = function (Container $c)
{
    return new \Psr3\Log\NullLogger();
}
would be sufficient as a start.

This way Add-ons could just use the logger without having roll their own thing (eg. reinventing the wheel) and if an Admin (or Developer) would like to make actual use of the Logger they could easily use an Add-on to do smth. useful.
 
Top Bottom