Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel : How to Log INFO to separate file

How to specify a separate file for logging INFO in Laravel 5.1?

Any immediate help will be highly appreciable. Thanks

like image 639
Creative Learner Avatar asked Sep 13 '15 17:09

Creative Learner


People also ask

How do I enable log files in Laravel?

You should be checking the root directory and not the app directory. Look in $ROOT/storage/laravel. log not app/storage/laravel. log , where root is the top directory of the project.

Where are Laravel logs stored?

By default, Laravel is configured to create a single log file for your application, and this file is stored in app/storage/logs/laravel. log .


1 Answers

Do you want to specifically log info to one log file and another log type to another location? My solution might not help in that case, but could still be useful.

To write a log file to another location, use the method useDailyFiles or useFiles, and then info to log to the log file at the path you just specified. Like so:

    Log::useDailyFiles(storage_path().'/logs/name-of-log.log');     Log::info([info to log]); 

The first parameter for both methods is the path of the log file (which is created if it doesn't already exist) and for useDailyFiles the second argument is the number of days Laravel will log for before erasing old logs. The default value is unlimited, so in my example I haven't entered a value.

like image 126
TimothyBuktu Avatar answered Oct 16 '22 15:10

TimothyBuktu