Download the PHP package serhii/tiny-logger without Composer
On this page you can find all versions of the php package serhii/tiny-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download serhii/tiny-logger
More information about serhii/tiny-logger
Files in serhii/tiny-logger
Package tiny-logger
Short Description Light weight composer package for file logging in PHP7.
License MIT
Homepage https://github.com/tiny-logger/tiny-logger
Informations about the package tiny-logger
Lightweight composer package for file logging with ability to send errors with webhook.
Set file path
For setting up the path globally for all the log files you can call setPath
method in your bootstrap file.
NOTE: If you want to use logger in a cron scripts or something like WordPress hook, you need to call
setPath()
at the very first step of the script execution, it means that your project might have multiple places where you need to set path for your logs. If you don't want to callsetPath()
you can just pass the path to atiny_log()
function as a third argument. See an example in the Usage section.
Supported PHP versions
- ✅ 7.2
- ✅ 7.3
- ✅ 7.4
- ✅ 8.0
- ✅ 8.1
- ✅ 8.2
- ✅ 8.3
Usage
This package comes with a function tiny_log()
where second and third arguments are not required.
You can also use Logger class if you want. It will do the same as using function.
`
Options
For using one of the available options you can optionally pass certain flag to tiny_log()
function as the second argument. If you also need to pass error type just separate them with the pipe |
character. See the example with option pos
:
Available options
pos
- Show position of the logger. In which file and on what line number it is. It is useful when you're debugging, to not forget where you put your logger. See the example of output:
Send logs with POST request
Tiny logger allows you to send logs as a json object on a specific endpoint. To enable this option you need to call enablePostRequest
method on Logger
class. To disable POST request use disablePostRequest
method.
Now if error occurs, json will be sent to http://my-site.com/webhook
endpoint with POST request.
If you need to customize the json object structure, you can pass array as the second argument on enablePostRequest
method.
Now you'll get json like this:
Each JsonFieldValue constant will be replaced with its value. For example JsonFieldValue::MESSAGE will be replaced with the error message. JsonFieldValue::TIMESTAMP will be replaced with error timestamp.
NOTE: If you want to use logger in a cron scripts or something like WordPress hook, you need to call
enablePostRequest
at the very first step of the script execution.
Get started
To install all php dependencies you need to have Composer PHP package manager installed on your machine. Then you need to run the command below in your root directory of the project.