zend-expressive-swoole icon indicating copy to clipboard operation
zend-expressive-swoole copied to clipboard

ISO 8601 log format

Open marc-mabe opened this issue 6 years ago • 2 comments
trafficstars

  • [x] I was not able to find an open or closed issue matching what I'm seeing.
  • [x] This is not a question. (Questions should be asked on chat (Signup here) or our forums.)

Currently it's impossible to define an own date format in the logger. The problem goes down to the usage of strftime which uses % for formating times as well as the other non common date formats.

Code to reproduce the issue

To log times in ISO 8601 format, according to the documentation this would look like the following. But as % is used already to parse the log format the formatter just generates useless output.

 'zend-expressive-swoole' => [
        'swoole-http-server' => [
            'logger' => [
                'format' => '%{%FT%T%z}t',
            ],
    ]
]

Suggestion 1

My recommended suggestion would to to use the more common date format instead of strftime because, yea it's more common in PHP as it's the same as in DateTime and it does not use % to it's much more readable and much simpler to parse.

Suggestion 2

Another suggestion would be to "fix" the log formatter and combine replaceConstantDirectives and replaceVariableDirectives on parsing to make sure %{format}t gets used by the variable directives no matter how the format looks like.

marc-mabe avatar Feb 13 '19 08:02 marc-mabe

OK there is a workaround but it's still super hard to create a useful output as well as read the format to understand what's going on.

%{%%FT%%T%%z}t This basically escapes the % character of the format and works but as I sad it's super hard to read/write and also it's not performant as it needs to replace the characters multiple times.

marc-mabe avatar Feb 13 '19 08:02 marc-mabe

This repository has been closed and moved to mezzio/mezzio-swoole; a new issue has been opened at https://github.com/mezzio/mezzio-swoole/issues/2.

weierophinney avatar Dec 31 '19 21:12 weierophinney