Download the PHP package toropyga/flog without Composer
On this page you can find all versions of the php package toropyga/flog. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download toropyga/flog
More information about toropyga/flog
Files in toropyga/flog
Informations about the package flog
FLog
Logging class
Contents
- Overview
- Installation
- Configuration
- Usage
- Including the class file
- Initializing the class
- Setting parameters
- Saving a log line
- Saving an array of logs
Overview
The FLog class is designed to save the passed data to a file. It requires PHP version 7.1 or higher.
You can configure the maximum size of the resulting file and the retention period for log files. Log files will not exceed the specified size and will not be stored longer than the specified retention period.
Installation
The recommended way to install the FLog library is via Composer:
Configuration
Default parameters can be pre-configured either directly in the class itself, via named constants, or by passing parameters when the class is initialized. Named constants, if needed, are declared before the class is called (for example, in a configuration file) and define the default parameters.
- LOG_ROOT_PATH - path to the site's root directory; defaults to the current directory;
- LOG_PATH - name of the directory in which the logs directory is created;
- LOG_DIR - name of the logs directory;
- LOG_NAME - name of the log file;
- LOG_SIZE - maximum log file size in megabytes (MB);
- LOG_TIME - number of days for which logs are kept;
- LOG_LEVEL - default log level (debug, info, notice, warning, error, critical, alert, emergency);
- LOG_SAVE_NOW - whether to save the log line to the file immediately or save it as a batch at the end of execution
- LOG_CLEAR - whether to clean up the directory from old files
When initializing the class, you can pass an array with the following keys for configuration:
- log_root_dir - path to the root directory
- log_path - path to the logs directory relative to the root directory
- log_dir - name of the logs directory
- log_name - name of the log file
- log_max_size - maximum log file size in megabytes (MB)
- log_time - number of days for which logs are kept
- log_level - log level
- log_save_now - whether to save the log immediately or at the end of execution
- log_system_info - amount of service information included in the log ('full', 'advanced', 'simple')
- log_clear - whether to clean up the directory from old files
Usage
Including the class file
or using Composer
Initializing the class
or
Setting parameters
Configure the amount of service information included in the log. Accepted values:
- simple - date, level, uri
- advanced - ip, date, level, uri
- full - ip, date, level, uri, user agent
Set the log level. Accepted values: emergency, alert, critical, error, warning, notice, info, debug
Set the file name used for writing logs
Set the log storage method.
Accepts a number from 0 to 6, or a string (file - to a file, stdout - to the system output, db - to a database)
Numbers:
- 0 - save to a file
- 1 - save to STDOUT
- 2 - save to a database
- 3 - save to a file and STDOUT
- 4 - save to a file and a database
- 5 - save to STDOUT and a database
- 6 - save to a file, STDOUT, and a database
If a string is passed instead of a number, it can list several types separated by commas in any order ('file, db')
By default, logs are saved to a file only.
or
Connecting a database for writing logs to a database
Saving a log line
Preliminary log data.
The log text supports placeholder substitution. A placeholder variable is enclosed in curly braces. Substitution is performed using values from the context array, keyed by the name of the placeholder variable without the curly braces. (see the documentation, section 1.2)
debug level log
info level log
notice level log
warning level log
error level log
critical level log
alert level log
emergency level log
A generic variant is also available, with the log level specified explicitly
You can use the legacy variant
Saving an array of logs
All versions of flog with dependencies
toropyga/base Version *
toropyga/db Version *
ext-fileinfo Version *
ext-mbstring Version *