Skip to content

Commit dfbb7e6

Browse files
committed
Change logging date formatting string from strftime() to date().
strftime is deprecated and will be removed in PHP 9. SSP 2.0 is our chance to change this format as it's exposed to installers of SSP. The approch is to keep it simple and just change the format to PHP's built in date() function which remains supported. Also we do not try to localize the logging date/timestamps anymore. This matches the syslog approach that this format tried to mimic. We are using the day without leading zeroes now also to be a bit closer to how syslog does it.
1 parent 05f4997 commit dfbb7e6

4 files changed

Lines changed: 10 additions & 7 deletions

File tree

config-templates/config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@
302302
* are:
303303
*
304304
* - %date{<format>}: the date and time, with its format specified inside the brackets. See the PHP documentation
305-
* of the strftime() function for more information on the format. If the brackets are omitted, the standard
305+
* of the date() function for more information on the format. If the brackets are omitted, the standard
306306
* format is applied. This can be useful if you just want to control the placement of the date, but don't care
307307
* about the format.
308308
*
@@ -322,7 +322,7 @@
322322
* - %msg: the message to be logged.
323323
*
324324
*/
325-
//'logging.format' => '%date{%b %d %H:%M:%S} %process %level %stat[%trackid] %msg',
325+
//'logging.format' => '%date{M j H:i:s} %process %level %stat[%trackid] %msg',
326326

327327
/*
328328
* Choose which facility should be used when logging with syslog.

docs/simplesamlphp-upgrade-notes-2.0.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ Configuration changes
3434
---------------------
3535
Quite some options have been changed or removed. We recommend to start with a fresh
3636
template from `config-templates/` and migrate the settings you require to the new
37-
config file= manualy.
37+
config file manualy.
38+
39+
The date formatting when specifying a custom logging string has been changed from PHP's
40+
deprecated `strftime()` format to PHP's `date()` format.
3841

3942
Configuration options that have been removed:
4043
- languages[priorities]

lib/SimpleSAML/Logger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Logger
9191
* general the options are:
9292
*
9393
* - %date{<format>}: the date and time, with its format specified inside the brackets. See the PHP documentation
94-
* of the strftime() function for more information on the format. If the brackets are omitted, the standard
94+
* of the date() function for more information on the format. If the brackets are omitted, the standard
9595
* format is applied. This can be useful if you just want to control the placement of the date, but don't care
9696
* about the format.
9797
*
@@ -113,7 +113,7 @@ class Logger
113113
*
114114
* @var string The format of the log line.
115115
*/
116-
private static string $format = '%date{%b %d %H:%M:%S} %process %level %stat[%trackid] %msg';
116+
private static string $format = '%date{M j H:i:s} %process %level %stat[%trackid] %msg';
117117

118118
/**
119119
* This variable tells if we have a shutdown function registered or not.

lib/SimpleSAML/Logger/FileLoggingHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ public function log(int $level, string $string): void
112112

113113
$matches = [];
114114
if (preg_match('/%date(?:\{([^\}]+)\})?/', $this->format, $matches)) {
115-
$format = "%b %d %H:%M:%S";
115+
$format = "M j H:i:s";
116116
if (isset($matches[1])) {
117117
$format = $matches[1];
118118
}
119119

120120
array_push($formats, $matches[0]);
121-
array_push($replacements, strftime($format));
121+
array_push($replacements, date($format));
122122
}
123123

124124
$string = str_replace($formats, $replacements, $string);

0 commit comments

Comments
 (0)