1. Go to this page and download the library: Download originphp/log library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
Log::emergency('system is unusable');
Log::alert('action must be taken immediately');
Log::critical('a critical condition');
Log::error('an error has occured');
Log::warning('warning low disk space');
Log::notice('normal, but significant, condition');
Log::info('informational message');
Log::debug('debug-level message');
use Origin\Log\Log;
Log::config('file',[
'engine' => 'File',
'file' => '/var/www/logs/application.log',
'size' => 10485760, // or 10MB,
'rotate' => 3
]);
use Origin\Log\Log;
Log::config('default',[
'engine' => 'Email',
'to' => '[email protected]', // string email only
'from' => ['[email protected]' => 'Web Application'] // to add a name, use an array,
'host' => 'smtp.example.com',
'port' => 465,
'username' => '[email protected]',
'password' => 'secret',
'timeout' => 5,
'ssl' => true,
'tls' => false
]);
use Origin\Log\Log;
Log::config('default',[
'engine' => 'Console'
]);
use Origin\Log\Log;
Log::config('default',[
'engine' => 'Syslog'
]);
use Origin\Log\Log;
// Logs all items to file
Log::config('default',[
'engine' => 'File',
'file' => '/var/www/logs/master.log'
]);
// Send import log items by email
Log::config('critical-emails',[
'engine' => 'Email',
'to' => '[email protected]',
'from' => ['[email protected]' => 'Web Application'],
'levels' => ['critical','emergency','alert'],
'host' => 'smtp.gmail.com',
'port' => 465,
'username' => '[email protected]',
'password' => 'secret',
'ssl' => true,
]);
// Create a seperate log for everything from the payments channel
Log::config('payments',[
'engine' => 'File',
'file' => '/var/www/logs/payments.log',
'channels' => ['payments']
]);
namespace App\Log\Engine;
use Origin\Log\Engine\BaseEngine;
class DatabaseEngine extends BaseEngine
{
/**
* Setup your default config here
*
* @var array
*/
protected $defaultConfig = [];
/**
* This will be called when the class is constructed
*
* @var array
*/
protected function initialize(array $config) : void
{
}
/**
* Logs an item
*
* @param string $level e.g debug, info, notice, warning, error, critical, alert, emergency.
* @param string $message 'this is a {what}'
* @param array $context ['what'='string']
* @return void
*/
public function log(string $level, string $message, array $context = []) : void
{
$message = $this->format($level, $message, $context);
// do something
}
}
use Origin\Log\Log;
Log::config('default',[
'className' => 'App\Log\Engine\DabaseEngine'
]);
use Origin\Log\Logger;
$logger = new Logger([
'engine' => 'File',
'file' => '/var/www/logs/master.log'
]);