Download the PHP package schalkt/log without Composer
On this page you can find all versions of the php package schalkt/log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package log
Simple and easy configurable PHP log system
A simple log system with pattern based path and messages. Objects and arrays are automatically converted to prettified JSON. You can also create CVS files. No need log rotation, just delete the older log folders if necessary.
Install
composer require schalkt/log
Features
- pattern based logfile path:
/{TYPE}/{YEAR}/{YEAR}-{MONTH}/{TYPE}-{MONTH}-{DAY} - pattern based rows:
{DATE} | {STATUS} --- {MESSAGE} - objects and arrays converted to prettified JSON automatically
- customizable CSV row pattern:
'"{DATE}";{MESSAGE};"{BACKTRACE.CLASS}";"{BACKTRACE.FUNCTION}"' - logrotate not required due to the pattern-based log path
- multiple log types in config
Available log levels
Log::to()->info($message, $title = null);Log::to()->error($message, $title = null);Log::to()->critical($message, $title = null);Log::to()->warning($message, $title = null);Log::to()->notice($message, $title = null);Log::to()->debug($message, $title = null);Log::to()->exception(\Exception $ex, $title = null);Log::to('import')->error('Unique id required');Log::to('login')->notice($input, 'Invalid password');
Examples
Example folder structure with {TYPE}, {YEAR}, {MONTH} and {DATE} patterns
Use default config
Change default log folder
Add new config
Load custom configs from file
Configs
Default config
Custom config file
Available variables in patterns
{MESSAGE}<- first parameter of function (required, string, array, object, any){TITLE}<- second parameter of function (not required, string or number){TYPE}<- came from log config{STATUS}<- info, error, critical, warning, notice, debug, or exception{REQUEST}<- dump $_REQUEST{RAWBODY}<- file_get_contents('php://input'){EOL}<- PHP_EOL{DATE}<- date by config "format_date", default "Y-m-d H:i:s"{YEAR}<- date('Y'){MONTH}<- date('m'){DAY}<- date('d'){HOUR}<- date('H'){MIN}<- date('i'){IP}: Client's IP address.{USER_AGENT}: User's browser user agent.{REQUEST_METHOD}: HTTP request method (e.g., GET, POST).{REQUEST_URI}: The requested URI.{SESSION_ID}: Current session ID.{HOSTNAME}: Server's hostname.{EXECUTION_TIME}: Script execution time.{MEMORY_USAGE}: Current memory usage.{MEMORY_PEAK_USAGE}: Peak memory usage.
Flush Logs
The flush method allows you to delete all log files under a specific log type's folder. By default, it also deletes the base folder. However, you can control this behavior by passing a boolean parameter to the method.
Usage
If the folder is protected (e.g., root directories like ./ or ../), the method will throw a LogException to prevent accidental deletion.