Skip to content

PHP Proxy Logger Component - Put Back Some Freedom And Silence In You Logs

So what is this component all about?
Basically it is a self developed "Proxy Logger" for php. Furthermore, this projects extends the proxy logger with an buffer and again with a trigger to flush or clean this buffer.

What does a "Proxy Logger" for php mean? It means a proxy for all loggers which implements the "PSR-3 Logger Interface". The proxy forwards all log requests to all attached loggers.
By using the provided "Buffer Logger", you are able to manipulate the forwarding of the log requests to all attached loggers.
Additionally, you can manipulate the buffering itself by using the available "Buffer Manipulators". This enables the possibility to set a trigger for log level to regulate the forwarding of all log requests to all attached loggers.

By the time of this writing, the component is shipped with two manipulators, the "BypassBuffer" and the "FlushBufferTrigger".
You can use the "Bypass Buffer" to regulate which log level bypasses the buffer and are forwarded directly to all attached loggers. The "Flush Buffer Trigger" enables the way to mark a log level as trigger. If this log level is triggerd, the buffer will be flushed which means that all buffered log requests are forwarded to all attached loggers.

After writing about all the fundamental knowledge, lets move on to the "Upward Flush Buffer". The upward flush buffer extends the idea of a triggerd buffer flush by the concept of triggering this flush also if a log level of a higher priority is called. To keep it short, you can define "if at least this log level is called, flush the buffer".

The whole component is shipped with a log of examples.
Since the upward flush buffer trigger is the crown jewel of the component, i want to quote the output of the upward flush buffer trigger versus normal logger example.


----------------------------------------
First run with normal logger without log level restriction.
----------------------------------------
[1381003509] [debug] [processing id 1]
[1381003509] [info] [collection information and data id: 1]
[1381003509] [debug] [done]
[1381003509] [debug] [processing id 3]
[1381003509] [info] [collection information and data id: 3]
[1381003509] [info] [data can not handled with this process, queueing data to manual processing list]
[1381003509] [debug] [done]
[1381003509] [debug] [processing id 8]
[1381003509] [info] [collection information and data id: 8]
[1381003509] [info] [logical problem in data on key 3]
[1381003509] [notice] [trying to recalculate data]
[1381003509] [info] [setting data value of key 7 to default]
[1381003509] [debug] [finished]
[1381003509] [debug] [processing id 4]
[1381003509] [info] [collection information and data id: 4]
[1381003509] [debug] [done]
[1381003509] [debug] [processing id 5]
[1381003509] [info] [collection information and data id: 5]
[1381003509] [info] [logical problem in data on key 6]
[1381003509] [notice] [trying to recalculate data]
[1381003509] [warning] [setting data value of key 7 to default not possible]
[1381003509] [notice] [trying to revert modification]
[1381003509] [error] [runtime data and data in storage differs, can not revert modification]
[1381003509] [critical] [lost connection to storage]
[1381003509] [alert] [can not unlock and schedule processing to id 5]
[1381003509] [debug] [done]
[1381003509] [debug] [processing id 6]
[1381003509] [critical] [lost connection to storage]
[1381003509] [alert] [can not unlock and schedule processing to id 6]
[1381003509] [debug] [done]
----------------------------------------
Second run with normal logger and log level restriction to warning and above.
----------------------------------------
[1381003509] [warning] [setting data value of key 7 to default not possible]
[1381003509] [error] [runtime data and data in storage differs, can not revert modification]
[1381003509] [critical] [lost connection to storage]
[1381003509] [alert] [can not unlock and schedule processing to id 5]
[1381003509] [critical] [lost connection to storage]
[1381003509] [alert] [can not unlock and schedule processing to id 6]
----------------------------------------
Third run with manipulate buffer logger.
----------------------------------------
[1381003509] [debug] [processing id 5]
[1381003509] [info] [collection information and data id: 5]
[1381003509] [info] [logical problem in data on key 6]
[1381003509] [notice] [trying to recalculate data]
[1381003509] [warning] [setting data value of key 7 to default not possible]
[1381003509] [notice] [trying to revert modification]
[1381003509] [error] [runtime data and data in storage differs, can not revert modification]
[1381003509] [critical] [lost connection to storage]
[1381003509] [alert] [can not unlock and schedule processing to id 5]
[1381003509] [debug] [processing id 6]
[1381003509] [critical] [lost connection to storage]
[1381003509] [alert] [can not unlock and schedule processing to id 6]

What does this example show you?
The example shows typical log entries generated by a process that is dealing with a bunch of data.
"First run" is the regular massiv number of entries you have to deal with when you are running you logger without restrictions.
As you can see, it takes some time to figure out if something important happens. Even to find the place where something important happens is hard to find. The "second run" is an example when you run you logger in the restriction of "only log level of warning or above".
First of all, you notice that no debug or info messages are logged. But what is bad about that? You either miss important informations (like the process or data id) or you have to flood your logs with all informations for each log request.
Finally, the "third run" shows what i mean when i am writing about "putting back freedom and silence in your log files". The logger only logs when a critical log level is reached and provides all available informations. If nothing bad happens, nothing will be logged. Quite nice, isn't it?
If a part of the data is processed, the buffer is cleaned when nothing happens. If an important log level is triggerd, the buffer is flushed and all collected log requests are forwarded to all attached loggers.

If you find bugs, bad namings, ugly code, have ideas to improve this component, pull your code or became a participant :-).