Laravel Log Package
Simple API to write logs for Laravel., (*1)
Installation
Type in console:
composer require edujugon/laravel-log
Laravel 5.5 or higher?, (*2)
Then you don't have to either register or add the alias, this package uses Package Auto-Discovery's feature, and should be available as soon as you install it via Composer., (*3)
(Laravel < 5.5) Register the Log service by adding it to the providers array., (*4)
'providers' => array(
...
Edujugon\Log\Providers\LogServiceProvider::class
)
Publish the package's configuration file to the application's own config directory.
php artisan vendor:publish --provider="Edujugon\Log\Providers\LogServiceProvider" --tag="config"
The above command will generate a new file under your laravel app config folder called log.php, (*5)
Configuration
Update the log.php file with your data., (*6)
API List
path
path method sets the path where create / storage the log file., (*7)
Syntax, (*8)
Edujugon\Log\Log object path($path)
level
level method sets the logging level., (*9)
Available levels: emergency, alert, critical, error, warning, notice, info and debug., (*10)
Syntax, (*11)
Edujugon\Log\Log object level($level)
title
title method sets the title or main message to be written., (*12)
Syntax, (*13)
Edujugon\Log\Log object title($title)
line
line method sets a line below the title., (*14)
Notice that you can call this method as many time as lines you need to be written., (*15)
Syntax, (*16)
Edujugon\Log\Log object line($line)
logname
name method sets the logger name., (*17)
By default this name is "my-logger", (*18)
Syntax, (*19)
Edujugon\Log\Log object name($loggerName)
fileName
fileName method sets the file name., (*20)
Remember to put the name without any extension., (*21)
Syntax, (*22)
Edujugon\Log\Log object fileName($name)
days
days method sets amount of days to be kept in server., (*23)
Syntax, (*24)
Edujugon\Log\Log object days($days)
A value "0" means no day limit, (*25)
withoutDateTime
withoutDateTime method excludes datetime from log line., (*26)
Syntax, (*27)
Edujugon\Log\Log object withoutDateTime()
withoutLoggerDetails
withoutLoggerDetails method excludes logger details from log line., (*28)
Syntax, (*29)
Edujugon\Log\Log object withoutLoggerDetails()
Exclude logger name and level, (*30)
write
write method writes in log file., (*31)
Syntax, (*32)
boolean write()
Usage samples
$log = new Log();
$log->fileName('my-personal-log')
->title('Stored new record')
->line('the record id is 3')
->line('Stored by John')
->line('This is antoher line')
->days(3)
->write();
Also can do it by its Facade:, (*33)
Log::fileName('my-personal-log')
->title('Stored new record')
->line('the record id is 3')
->line('Stored by John')
->line('This is antoher line')
->write();