Elasticsearch logger #15784
DestinyMKas
started this conversation in
Show and tell
Replies: 1 comment 4 replies
-
Fantastic!! Would you consider adding this in the incubator repo? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I made simple logger which output log record to elasticsearch.
Requirements
It is tested on phalcon 5.0.0alpha6 version and definitely doesn't works on phalcon <5 versions.
I use elasticsearch 7.15.2. Not sure does it works on other versions.
Also I use elasticsearch library:
Code
Elasticsearch logger adapter
Elasticsearch logger formatter
You can choose any path to save it, just don't forget to change namespaces & uses
Dependency injection config, should be inserted into
services.php
Basically that's it what needs to be done for basic use of logger.
ES template:
Setup elasticsearch index template, documentation can be found here
I use following patterns for variable types:
Non blocking logging
If you want to log events during web request, most likely you don't want to block response. To do it, I use transaction to write all logs to memory and on terminate script push records to elasticsearch. The example works on php-fpm, not sure about apache mod/fastcgi.
Don't use on cli long running scripts! Transaction keeps all records in memory, so it can consume all your free memory.
I added transaction begin just after autoloader:
And transaction commit on terminate:
Example
How the record looks like:
Beta Was this translation helpful? Give feedback.
All reactions