1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PSR3-compatible generic logging facility

Discussion in 'XenForo Suggestions' started by Sim, Mar 4, 2015.

  1. Sim

    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.
     
    NixFifty, lazy llama, Kirby and 6 others like this.
  2. Sim

    Sim Well-Known Member

    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.
     
    Xon likes this.
  3. Sim

    Sim Well-Known Member

    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!
     
  4. Kirby

    Kirby Member

    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.
     
  5. Xon

    Xon Well-Known Member

    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.
     
    Sim likes this.
  6. Sim

    Sim Well-Known Member

    ... 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.
     
    Xon likes this.

Share This Page