99

I'm debugging a JSON endpoint and need to view internal server errors. However, my app/storage/logs dir is empty and it seems there are no other directories dedicated to logs in the project. I've tried googling the subject to no avail.

How can I enable logging, if it's not already enabled and view the logs?

miken32
  • 42,008
  • 16
  • 111
  • 154
Alex Lomia
  • 6,705
  • 12
  • 53
  • 87
  • Can you please tell what is your current setup? SO and http server. – Álvaro Guimarães May 31 '16 at 00:58
  • 1
    By default Laravel should log everything in the `storage` folder. Does your configuration have the correct permissions to store in the logs? You can check your apache logs in `/var/log/apache2/error.log` - this will tell you if you don't have the correct permissions. – James May 31 '16 at 00:58
  • 2
    which method are you using for logging? `error_log` would use the default PHP log directory and `Log::error` would use the default Laravel log directory – Edwin May 31 '16 at 01:14
  • 1
    @ÁlvaroGuimarães I'm not sure how to do that, but everything is set to defaults – Alex Lomia May 31 '16 at 01:19
  • @James According to Denis Mysenko, who answered the question, the permissions are not an issue – Alex Lomia May 31 '16 at 01:21
  • @Edwin I'm using the `errorlog` and the logs are indeed in the default PHP logging dir! Thank you – Alex Lomia May 31 '16 at 01:29

6 Answers6

120
  • Ensure debug mode is on - either add APP_DEBUG=true to .env file or set an environment variable

  • Log files are in storage/logs folder. laravel.log is the default filename. If there is a permission issue with the log folder, Laravel just halts. So if your endpoint generally works - permissions are not an issue.

  • In case your calls don't even reach Laravel or aren't caused by code issues - check web server's log files (check your Apache/nginx config files to see the paths).

  • If you use PHP-FPM, check its log files as well (you can see the path to log file in PHP-FPM pool config).

Denis Mysenko
  • 6,366
  • 1
  • 24
  • 33
  • The `laravel.log` file is absent, though the logs are present in the default PHP log dir – Alex Lomia May 31 '16 at 01:28
  • Either there are no exceptions/errors on Laravel side or Laravel doesn't have enough permissions to write to the log file. What do you see in HTTP client - do you see any error at all? – Denis Mysenko May 31 '16 at 01:35
  • No, there are no displayed errors in the HTTP client. Didn't you just say, that the Laravel would just halt if there were any permission issues? – Alex Lomia May 31 '16 at 01:50
  • Yep, then that could be an issue. Check under what user your web process is running, ensure that this user has permissions to write to 1) storage/logs 2) storage/framework 3) bootstrap/cache folders – Denis Mysenko May 31 '16 at 02:07
22

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.

Dov Benyomin Sohacheski
  • 7,133
  • 7
  • 38
  • 64
Ali
  • 331
  • 3
  • 5
  • 10
    I think it's *storage/logs/laravel.log* not *storage/laravel.log*, relative to the project's root directory. – Kenny Evitt Aug 06 '18 at 18:54
  • where is the $root at? if I do this: ```cd /``` i see some folders but not storage, the only thing that has a storage folder is inside the app folder but same as OP, I have no ```laravel.logs``` file, thank you. – Eduardo May 20 '21 at 19:57
4

The location of the log file can be found inside channels array config/logging.php (See below)

enter image description here

In case if some one is looking to write to the single channel, using Laravel's Log Facade, here's how to do.

Log::channel('single')->info('Your message');

Anjana Silva
  • 8,353
  • 4
  • 51
  • 54
3

In Laravel 6, by default the logs are in:

storage/logs/laravel.log

Luis Cabrera Benito
  • 1,558
  • 13
  • 21
0

Ensure that APP_DEBUG=true is set to on on you .env

If you want to easily check your storage log you can install:

https://github.com/rap2hpoutre/laravel-log-viewer

mpalencia
  • 5,481
  • 4
  • 45
  • 59
0

You can access the location programmatically by storage_path() . '/logs':

$logFiles = array_filter(
    scandir(storage_path() . '/logs'), 
    fn($fn) => !str_starts_with($fn,'.') // filter everything that begins with dot
);
raveren
  • 17,799
  • 12
  • 70
  • 83