# [PATCH] Friendly log messages for CLI server

- Thread: https://externals.io/message/53640
- Original archive: https://news-web.php.net/php.internals/53640
- Started by Arpad Ray on 2011-06-28T22:37:15+00:00
- Messages: 13
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #53640 — Arpad Ray — 2011-06-28T22:37:15+00:00

URL: https://externals.io/message/53640#53640

Hi,

This little patch makes the following changes to the CLI web server's
console logging:
- Compacts messages to one line, so a 404 doesn't occupy three lines.
- Includes the response status code
- Colours messages according to their response code (success=green,
client error=yellow, server error=red)
- Appends the error message when there's a fatal PHP error

Here's an example:
http://spellign.com/patches/cli-before.png
http://spellign.com/patches/cli-after.png

And the patch:
http://spellign.com/patches/php-trunk-cli-server-messages.patch

I'd appreciate any feedback.

Regards,

Arpad

---

## #53641 — Ferenc Kovacs — 2011-06-28T22:39:05+00:00

URL: https://externals.io/message/53640#53641 · In reply to: #53640

> Hi,
>
> This little patch makes the following changes to the CLI web server's
> console logging:
> - Compacts messages to one line, so a 404 doesn't occupy three lines.
> - Includes the response status code
> - Colours messages according to their response code (success=green,
> client error=yellow, server error=red)
> - Appends the error message when there's a fatal PHP error
>
> Here's an example:
> http://spellign.com/patches/cli-before.png
> http://spellign.com/patches/cli-after.png
>
> And the patch:
> http://spellign.com/patches/php-trunk-cli-server-messages.patch
>
> I'd appreciate any feedback.
>
> Regards,
>
> Arpad
>
> --
> 
> 
>
>

I would love to have this. :)

Tyrael

---

## #53642 — johannes@schlueters.de — 2011-06-28T23:19:09+00:00

URL: https://externals.io/message/53640#53642 · In reply to: #53640

> - Colours messages according to their response code (success=green,
> client error=yellow, server error=red)

I would prefer if this would be an ini option (if (cli_web_server.color
&& isatty) color = true) default can be on, but I've seen cases where
such magic failed and created hard-to use results (due to control
sequences in log files or such).

johannes

---

## #53643 — jerome@loyet.net — 2011-06-28T23:30:07+00:00

URL: https://externals.io/message/53640#53643 · In reply to: #53642

2011/6/29 Johannes Schlüter <johannes@schlueters.de>:
> 
> > […]
>
> I would prefer if this would be an ini option (if (cli_web_server.color
> && isatty) color = true) default can be on, but I've seen cases where
> such magic failed and created hard-to use results (due to control
> sequences in log files or such).
>

I agree with johannes. Color should be an option, all term does not
handle them correctly. Also, color control sequences are just killing
a log file.

++ Jerome

---

## #53644 — Christopher Jones — 2011-06-28T23:31:34+00:00

URL: https://externals.io/message/53640#53644 · In reply to: #53642

> 
> > […]
>
> I would prefer if this would be an ini option (if (cli_web_server.color
> &&  isatty) color = true) default can be on, but I've seen cases where
> such magic failed and created hard-to use results (due to control
> sequences in log files or such).
>
> johannes
>
>
>

I'm -1 on the color coding for a few reasons: (i) it can be done
outside of PHP (ii) forcing a particular color coding is problematic
for many users (iii) the escape codes are not portable.

The other items in the patch have merit.

If you're looking at the web server code, perhaps you can sort out the
issues with subdirectories and include()?  Moriyoshi has gone quiet
on it.

Chris

-- 
Email: christopher.jones@oracle.com
Tel:  +1 650 506 8630
Blog:  http://blogs.oracle.com/opal/

---

## #53649 — Derick Rethans — 2011-06-29T10:45:01+00:00

URL: https://externals.io/message/53640#53649 · In reply to: #53643

> 2011/6/29 Johannes Schlüter <johannes@schlueters.de>:
> > […]
> 
> I agree with johannes. Color should be an option, all term does not
> handle them correctly. Also, color control sequences are just killing
> a log file.

That's why the patch first checks whether stdout is actually a tty, so 
your log file will not have ansi control characters.

Derick

---

## #53650 — johannes@schlueters.de — 2011-06-29T11:07:37+00:00

URL: https://externals.io/message/53640#53650 · In reply to: #53649

> That's why the patch first checks whether stdout is actually a tty, so 
> your log file will not have ansi control characters.

While that check is not always the best/good thing. For instance if
you're using script(1) to log a terminal session you will end up with a
log file with control sequences.

Script started on June 29, 2011 12:59:59 PM CEST
$ cat test.c
#include <unistd.h>

int main() {
        printf("%i\n", isatty(STDOUT_FILENO));
        return 0;
}
       
$ gcc -otest test.c
$ ./test
1
$ exit
script done on June 29, 2011 01:02:11 PM CEST

And then there are people using "strange" backgrounds or have trouble
identifying specific colors - so I think it should be made optional.

johannes

---

## #53652 — Pierre Joye — 2011-06-29T11:24:54+00:00

URL: https://externals.io/message/53640#53652 · In reply to: #53640

hi,

Good idea :)

However I would prefer to have that enabled optionally. CLI is widely
used for automated tasks with logs created using std* redirects. I
would not like to have the color escape codes in these logs.

Also please open a FR at bugs.php.net and attach the patch(es) to it, thanks!

Cheers,


> Hi,
>
> This little patch makes the following changes to the CLI web server's
> console logging:
> - Compacts messages to one line, so a 404 doesn't occupy three lines.
> - Includes the response status code
> - Colours messages according to their response code (success=green,
> client error=yellow, server error=red)
> - Appends the error message when there's a fatal PHP error
>
> Here's an example:
> http://spellign.com/patches/cli-before.png
> http://spellign.com/patches/cli-after.png
>
> And the patch:
> http://spellign.com/patches/php-trunk-cli-server-messages.patch
>
> I'd appreciate any feedback.
>
> Regards,
>
> Arpad
>
> --
> 
> 
>
>



-- 
Pierre

@pierrejoye | http://blog.thepimp.net | http://www.libgd.org

---

## #53694 — david.zuelke@bitextender.com — 2011-06-30T05:08:43+00:00

URL: https://externals.io/message/53640#53694 · In reply to: #53642

> 
> > […]
> 
> I would prefer if this would be an ini option (if (cli_web_server.color
> && isatty) color = true) default can be on, but I've seen cases where
> such magic failed and created hard-to use results (due to control
> sequences in log files or such).

The code could detect if it's outputting to a TTY or not and only use color codes if the output isn't redirected somewhere else.

David

---

## #53700 — johannes@schlueters.de — 2011-06-30T10:54:20+00:00

URL: https://externals.io/message/53640#53700 · In reply to: #53694

> 
> 
> > […]
> 
> The code could detect if it's outputting to a TTY or not and only use
> color codes if the output isn't redirected somewhere else.

It *is* checking this. And I showed an example (script(1)) where the
environment pretends to be a TTY and isn't. My suggestion was to add an
ini option in addition to the check.

johannes

---

## #53701 — Derick Rethans — 2011-06-30T11:24:26+00:00

URL: https://externals.io/message/53640#53701 · In reply to: #53700

> 
> > […]
> 
> It *is* checking this. And I showed an example (script(1)) where the
> environment pretends to be a TTY and isn't. My suggestion was to add an
> ini option in addition to the check.

I'm fine with that, but let's leave it set to 1 by default? People with 
complex requirements can then turn it off if they want to.

regards,
Derick

---

## #53702 — Richard Quadling — 2011-06-30T12:31:58+00:00

URL: https://externals.io/message/53640#53702 · In reply to: #53701

> 
>
> > […]
>
> I'm fine with that, but let's leave it set to 1 by default? People with
> complex requirements can then turn it off if they want to.
>
> regards,
> Derick
>
> --
> 
> 
>

In Windows, there is no default colouring support at the console, so
it would make sense if it was off by default.

I use a tool called ANSICon which provides the colouring support
(http://en.wikipedia.org/wiki/ANSI_escape_code#Support and source+bins
at http://adoxa.110mb.com/ansicon/).

So, for me turning it on would work for me.

Richard.

-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

---

## #53703 — Pierre Joye — 2011-06-30T12:47:04+00:00

URL: https://externals.io/message/53640#53703 · In reply to: #53700

agreed, it should be optional and off by default. PHP never had such
feature either.

2011/6/30 Johannes Schlüter <johannes@schlueters.de>:
> 
> > […]
>
> It *is* checking this. And I showed an example (script(1)) where the
> environment pretends to be a TTY and isn't. My suggestion was to add an
> ini option in addition to the check.
>
> johannes
>
>
>
> --
> 
> 
>
>



-- 
Pierre

@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
