-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve #22 by using contributed new function from BohwaZ to fix depr… #23
Conversation
so there seem to be some difficulties with supporting this on 5.6 but also not sure how important it is to still support PHP5.6 these days |
…deprecation issue in php8.1
@@ -25,7 +25,10 @@ | |||
define('PEAR_LOG_TYPE_DEBUG', 2); /* Use PHP's debugging connection */ | |||
define('PEAR_LOG_TYPE_FILE', 3); /* Append to a file */ | |||
define('PEAR_LOG_TYPE_SAPI', 4); /* Use the SAPI logging handler */ | |||
|
|||
if (!function_exists('PHP81_BC\strftime')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit overkill?
There is no other way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@williamdes I think previously I found that if someone had pulled in https://packagist.org/packages/php81_bc/strftime via composer then without this if there were errors
This is a pretty heavy solution (in terms of both the code dependency and runtime overhead). I think I'd prefer a solution like this:
|
@jparise so the php8.1-strftime.php function is designed to do the first part of 2. As for the 2nd part do we assume that if they have % in the string it will be the strftime format or not? |
I would differentiate the two formats based on configuration key names: |
@jparise given that strftime did locale work as well as formatting a date do you think this might be appropriate https://www.php.net/manual/en/intldateformatter.format.php it would mean having to have php-intl installed or should we do some kind of fall back process if no php-intl use date_format? |
I'm not sure I see a strong benefit to internationalization support in log lines. The output isn't meant to be user-facing. |
I'm happy to drop the locale support if it is your preference I was just thinking about it from a consistency point of view |
That's kind of the rub (as per "80-20 rule") - date-time functionality (generally conceived) includes elements that are internationalized. But for logging specifically, you could hardcode one format (ISO 8601) and it would serve 80% of the use-cases. It's the last 20% that's harder. There are edge-cases around the PHP version, PHP extensions+packages, timezones, tzdata, locales, locale data, formatting-placeholders... not to mention the subjective expectations of the various downstream apps+users. FWIW... you might consider a property /**
* @var callable
*/
var $_timeFormatter;
public function __construct(...) {
...
if (!empty($conf['timeFormatter'])) {
$this->_timeFormatter = $conf['timeFormatter'];
} elseif (!empty($conf['timeFormat'])) {
// Support for older `timeFormat`. Only useful on systems that support strftime() well.
$this->_timeFormatter = function() {
return strftime($conf['timeFormat']);
};
}
else {
// Traditional default format
$this->_timeFormatter = function() { return date("M d H:i:s"); }
} That still accepts $log = new Log_foo(..., [
// Basic formatting rule
'timeFormatter' => fn() => date('Y-m-d H:i:s O'),
// Alternative formatting rules. Diff approaches to timezones, locales, placeholders, dependencies, etc
// 'timeFormatter' => fn() => gmdate('Y-m-d H:i:s O'),
// 'timeFormatter' => fn() => gmdate('c'),
// 'timeFormatter' => fn() => strftime("%b %d %H:%M:%S"),
// 'timeFormatter' => fn() => \PHP81_BC\strftime("%b %d %H:%M:%S", NULL, 'C')),
// 'timeFormatter' => fn() => \PHP81_BC\strftime("%b %d %H:%M:%S", NULL, $GLOBALS['myapp']->getStandardTimezone())),
]); Anyway, that's a suggestion. But the other approaches are also fine. |
Yes, understood. My reaction was primarily about a dependency on I have no general concern about providing locale-aware timestamps in log output. |
Hi. |
I don't plan on merging this pull request in its current form, but it could be revised based on the discussion above. |
Thanks for your contribution! I'm going to close this in favor of the approach used by #25. |
…ecation issue in php8.1
ping @jparise not sure what you think of this and the package I got was found here https://packagist.org/packages/php81_bc/strftime which was based off this gist https://gist.github.com/bohwaz/42fc223031e2b2dd2585aab159a20f30