Reputation: 2347
PHP has a built in file server for testing and development purposes.
After a page was opened in a web browser, the console output of the server looks like this:
$ php -S localhost:8000
PHP 7.2.8 Development Server started at Sun Feb 9 23:09:17 2020
Listening on http://localhost:8000
Document root is /_PATHTOFILE_
Press Ctrl-C to quit.
[Sun Feb 9 23:09:19 2020] ::1:57697 [200]: /
[Sun Feb 9 23:09:19 2020] ::1:57698 [404]: /doesnt-exist.js - No such file or directory
How can I filter out all lines that include [200]
, as I'm only interested in warnings and errors?
I have unsucessfully tried the following:
$ php -S localhost:8000 | grep --line-buffered --invert-match "200" | awk '{print $3}'
$ php -S localhost:8000 | awk '!/200/{print $3}'
Both commands don't filter the lines, they just log the following:
[Sun Feb 9 23:09:19 2020] ::1:57697 [200]: /
[Sun Feb 9 23:09:19 2020] ::1:57698 [404]: /doesnt-exist.js - No such file or directory
What am I missing here?
Upvotes: 0
Views: 181
Reputation: 5415
Logs of php -S ... are printed to stderr not stdout, you need to filter stderr also. Without filtering:
$ php -S localhost:8888
PHP 5.6.40-0+deb8u7 Development Server started at Sun Feb 23 12:58:30 2020
Listening on http://localhost:8888
Document root is /home/sorin/tmp
Press Ctrl-C to quit.
[Sun Feb 23 12:58:33 2020] this is an error
[Sun Feb 23 12:58:33 2020] 127.0.0.1:52825 [200]: /test.php
^C
Redirecting stderr to stdout:
php -S localhost:8888 2>&1 | grep -v '\[200\]'
[Sun Feb 23 12:59:41 2020] this is an error
Test file:
cat test.php
<?php
error_log('this is an error');
Upvotes: 1