Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

seamuslee001
Copy link
Contributor

…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

@seamuslee001
Copy link
Contributor Author

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

@williamdes
Copy link

@@ -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')) {

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?

Copy link
Contributor Author

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

@jparise
Copy link
Member

jparise commented Oct 31, 2023

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:

  • Choose an "ideal" formatter (e.g. date_format) that we'd want to use going forward.
  • Provide a helper function that converts existing strftime format strings to the new format, and use it to automatically "upgrade" existing timeFormat configuration values to the new dateFormat configuration format when logger instances are constructed (and warn when the old timeFormat keys are used).
  • Significantly bump the package version to reflect these changes.

@seamuslee001
Copy link
Contributor Author

@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?

@jparise
Copy link
Member

jparise commented Oct 31, 2023

@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: timeFormat vs dateFormat.

@seamuslee001
Copy link
Contributor Author

@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?

@jparise
Copy link
Member

jparise commented Oct 31, 2023

@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.

@seamuslee001
Copy link
Contributor Author

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

@totten
Copy link

totten commented Oct 31, 2023

I'm not sure I see a strong benefit to internationalization support in log lines. The output isn't meant to be user-facing.

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 timeFormatter (@var callable):

/**
 * @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 timeFormat. It gives the same default behavior as always, and the default is compatible with all environments. For the long-tail of timezone/locale/version/dependency issues, it allows the downstream to choose a balance.

$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.

@jparise
Copy link
Member

jparise commented Oct 31, 2023

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

Yes, understood. My reaction was primarily about a dependency on intl being available, which seems like a unnecessarily strong requirement for a logging framework.

I have no general concern about providing locale-aware timestamps in log output.

@sveneld
Copy link
Contributor

sveneld commented Jan 5, 2024

Hi.
So what you decided? Will be current pull request merged or another solution will be provided?

@jparise
Copy link
Member

jparise commented Jan 6, 2024

I don't plan on merging this pull request in its current form, but it could be revised based on the discussion above.

@sveneld
Copy link
Contributor

sveneld commented Jan 7, 2024

@jparise look my pull request #25

@jparise
Copy link
Member

jparise commented Jan 7, 2024

Thanks for your contribution! I'm going to close this in favor of the approach used by #25.

@jparise jparise closed this Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants