Stack trace assente in error.log

7 views
Skip to first unread message

Roger

unread,
Apr 26, 2022, 3:34:57 AM4/26/22
to
$ php -i | grep log_errors
log_errors => On => On
log_errors_max_len => 1024 => 1024
$ php -i | grep error_log
error_log => /var/log/error.log => /var/log/error.log
$ php -i | grep display_errors
display_errors => Off => Off
$ cat test.php
<?php
trigger_error(null);
throw new Exception;
$ php test.php
$ tail -n 5 /var/log/error.log
[26-Apr-2022 09:06:52 Europe/Berlin] PHP Notice: in
/tmp/tmp.FoceFGDBYx/test.php on line 2
[26-Apr-2022 09:06:52 Europe/Berlin] PHP Fatal error: Uncaught
Exception in /tmp/tmp.FoceFGDBYx/test.php:3
Stack trace:
#0 {main}
thrown in /tmp/tmp.FoceFGDBYx/test.php on line 3

Come vedete per la Notice non c'è lo stack trace, mentre per il Fatal
error si.
Perchè?

fmigliori

unread,
Apr 26, 2022, 9:29:37 AM4/26/22
to
Perché l'errore fatale interrompe lo script.

Roger

unread,
Apr 27, 2022, 11:57:55 AM4/27/22
to
Il 26/04/22 15:29, fmigliori ha scritto:
> Perché l'errore fatale interrompe lo script.

Embè?

Comunque ecco qualche altro esperimento.

$ php -i | grep log_errors
log_errors => On => On
$ php -i | grep error_log
error_log => /var/log/error.log => /var/log/error.log
$ php -i | grep display_errors
display_errors => Off => Off
$ php -r "trigger_error('');"
$ tail -n1 /var/log/error.log
[27-Apr-2022 17:40:34 Europe/Berlin] PHP Notice: in Command line code
on line 1

Lo stacktrace non c'è.
C'è da dire che però, dopo aver fatto qualche modifica a php.ini, lo
stack trace appare, ma sullo schermo (non in /var/log/error.log).

$ php -i | grep log_errors
log_errors => Off => Off
$ php -i | grep error_log
error_log => no value => no value
$ php -i | grep display_errors
display_errors => STDOUT => STDOUT
$ php -r "trigger_error('');"

Notice: in Command line code on line 1

Call Stack:
0.0000 392704 1. {main}() Command line code:0
0.0000 392704 2. trigger_error() Command line code:1

$ tail -n1 /var/log/error.log
[27-Apr-2022 17:40:34 Europe/Berlin] PHP Notice: in Command line code
on line 1

Non si può fare niente per includere lo stacktrace in /var/log/error.log?
Reply all
Reply to author
Forward
0 new messages