Monolog Logging Service

Monolog Logging Service 4.0.0

No permission to download

Sim

Well-known member
Sim submitted a new resource:

Monolog for XenForo 2 - Provides Monolog logging facilities for XenForo 2

This XenForo 2.0 addon adds logging functionality using the Monolog library from https://github.com/Seldaek/monolog

Usage Instructions

By default, this addon will log events to a file called internal_data/monolog.log - in later versions this will be configurable.

To use the default logging facility, do the following in your addon code:

PHP:
/** @var Monolog\Logger $logger */
$logger = \XF::app()['monolog']->default();

$logger->info('an info...

Read more about this resource...
 

Sim

Well-known member
@Sim does this include the hostname by default when logging an error?

I have implemented the "WebProcessor" processor functionality in Monolog, which includes the following fields from the $_SERVER superglobal record by default:
  • 'url' => 'REQUEST_URI',
  • 'ip' => 'REMOTE_ADDR',
  • 'http_method' => 'REQUEST_METHOD',
  • 'server' => 'SERVER_NAME',
  • 'referrer' => 'HTTP_REFERER',
... plus it is possible to adjust the functionality to include any additional field present in the record in the log output. You just need to turn on the "Add Web Extra Data" option.

1516219337920.png

See: https://github.com/Seldaek/monolog/blob/master/src/Monolog/Processor/WebProcessor.php#L45 ... we can even push our own $_SERVER record in, if the PHP superglobal record is insufficient or somehow hidden.

See: https://github.com/Seldaek/monolog/blob/master/doc/02-handlers-formatters-processors.md for a full list of pre-built handlers/processors that could be implemented as part of this addon (includes Redis and ElasticSearch log destinations). It's also fairly straight forward to add our own handlers/processors if required.

I'll definitely add HipChat and Slack functionality to this addon at some point, and potentially others when I get the chance or have the need.

I'm also thinking of hooking in to the logException function and having it log all exceptions generated by XenForo or addons - however, I would also like to have a bit more granularity in choosing the severity of those exceptions. For example, an exception generated when the ElasticSearch server is offline is far less critical than one when the payment processor is failing.

Eventually I'd like to implement a full ELK Stack (Elasticsearch, Logstash, Kibana) as a logging destination - but that's a bit lower down the priority list right now.
 
  • Like
Reactions: Xon

Floyd R Turbo

Well-known member
Not sure what this does, dumb it down for the rest of us lol!

It sounds like it sends anything written to any of the log files to a designated file and/or email address? So admin logs, change logs, server error logs, etc...if so, totally want this
 

Sim

Well-known member
Not sure what this does, dumb it down for the rest of us lol!

It sounds like it sends anything written to any of the log files to a designated file and/or email address? So admin logs, change logs, server error logs, etc...if so, totally want this

Not yet - right now, it's only providing an API you can use to log information from your own addons. It's a developer tool.

I may extend the capabilities to log other information generated by the XenForo core.

I'm thinking perhaps a "daily log digest" email might be useful? Log all of the various log data to files and then email those to you once per day:
  • Server error log
  • Moderator log
  • Admin log
  • Payment provider log
The trick is to find the balance between getting enough useful information versus getting so much information that it becomes useless.
 

Floyd R Turbo

Well-known member
One of my suggestions I had made was to somehow notify the admin(s) when server errors are thrown. Right now, there's nothing for this so the only way to know about them is by logging into ACP. A situation can arise where something breaks and errors are getting thrown left and right, but there's zero notification of this. It's a huge beef of mine, I want to know what is going on immediately. A simple hourly cron to send any server errors via email would be enough for me. I guess there's not enough demand for this though. I thought this addon might fill the gap. So on a tangent it would be nice to be able to select a frequency for each type of log I guess, that would be the best flexibility. Or if there is another addon that does this now, I just need to know about it :unsure:
 

Sim

Well-known member
I'm thinking a separate "Log Digest" addon might work better for this - will think about the use cases and see if I can throw something together.
 

Xon

Well-known member
@Sim definitely looks interesting! A better logging solution for XF2 would be great, since atm it has all the downsides of a flat log file but without any CLI utilities to parse it :(
 

AnimeAi

Member
Does this currently produce any logs you can't access through Xenforo normally or does it start logging new things?
 

Sim

Well-known member
Does this currently produce any logs you can't access through Xenforo normally or does it start logging new things?

Right now it is only a tool of use to developers who build their own addons and would like to include logging functionality - think of it more like an API.

For example, I have another addon which makes back-end calls to a 3rd party cloud API from a Cron task and because there is no UI for this, I don't know if it is operating correctly (unless it fails with an exception which is logged in the server error log).

I will use this addon to provide logging functionality such that I can log debugging messages from the API calls on my dev server, or more detailed error messages on my production server.

However, there is plenty of scope to expand the functionality to include logging additional information not currently captured by the admin UI for analytical or debugging purposes.
 

Sim

Well-known member
One of my suggestions I had made was to somehow notify the admin(s) when server errors are thrown. Right now, there's nothing for this so the only way to know about them is by logging into ACP. A situation can arise where something breaks and errors are getting thrown left and right, but there's zero notification of this. It's a huge beef of mine, I want to know what is going on immediately. A simple hourly cron to send any server errors via email would be enough for me. I guess there's not enough demand for this though. I thought this addon might fill the gap. So on a tangent it would be nice to be able to select a frequency for each type of log I guess, that would be the best flexibility. Or if there is another addon that does this now, I just need to know about it :unsure:

I'm thinking a separate "Log Digest" addon might work better for this - will think about the use cases and see if I can throw something together.

FYI @Floyd R Turbo - I just released this addon: LogDigest For XenForo 2 :D
 

Sim

Well-known member
Sim updated Monolog Logging Service with a new update entry:

v3.0.0 new addon_id

I am changing the structure of the addon_id I use for my addons - so this version is a re-release of the functionality currently available in v2.1.1, but with a new addon_id.

Note that you cannot directly upgrade from v2.1.1 - there are additional manual steps required - please see upgrade instructions below.

If you don't yet have v2.x installed, just install v3.x as you would normally do for any addon. If upgrading from v2.x of the addon, follow the instructions below...

Read the rest of this update entry...
 
  • Like
Reactions: Xon
Top