You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Kate Gray (Jira)" <ji...@apache.org> on 2019/10/29 21:16:00 UTC

[jira] [Comment Edited] (LOG4PHP-234) Two plugin using log4php produces Fatal, although include_once used

    [ https://issues.apache.org/jira/browse/LOG4PHP-234?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16962471#comment-16962471 ] 

Kate Gray edited comment on LOG4PHP-234 at 10/29/19 9:15 PM:
-------------------------------------------------------------

Yes, I can.  I'll be including a bit more documentation to help this in the future, but for now the easiest way is likely going to be a conditional include.  Something like this:

 
{code:java}
<?php
// Check that the class does not already exist.  If it does, skip the require.
if (!class_exists ('Logger')) {
    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'log4php' . DIRECTORY_SEPARATOR . 'Logger.php');
}

// Get a different logger depending on the plugin name
$plugin_name = 'wp-xyz';
$logger = Logger::getLogger ($plugin_name);{code}
require_once won't work, as each plugin has it's own copy of the library.  Instead, you can look for the class name, and only include it if it's not present.  That way, only the first library will be loaded, whichever plugin it is.

If the plugins are public and you wouldn't mind sharing the name, I'd like to test to make sure that we don't break compatibility for you with 2.3.1.

Kate


was (Author: kategray):
Yes, I can.  I'll be including a bit more documentation to help this in the future, but for now the easiest way is likely going to be a conditional include.  Something like this:

 
{code:java}
<?php
// Check that the class does not already exist.  If it does, skip the require.
if (!class_exists ('Logger')) {
    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'log4php' . DIRECTORY_SEPARATOR . 'Logger.php')
}

// Get a different logger depending on the plugin name
$plugin_name = 'wp-xyz';
$logger = Logger::getLogger ($plugin_name);{code}
require_once won't work, as each plugin has it's own copy of the library.  Instead, you can look for the class name, and only include it if it's not present.  That way, only the first library will be loaded, whichever plugin it is.

If the plugins are public and you wouldn't mind sharing the name, I'd like to test to make sure that we don't break compatibility for you with 2.3.1.

Kate

> Two plugin using log4php produces Fatal, although include_once used
> -------------------------------------------------------------------
>
>                 Key: LOG4PHP-234
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-234
>             Project: Log4php
>          Issue Type: Bug
>         Environment: ubuntu LTS 16
>            Reporter: Max UNGER
>            Priority: Critical
>
> Two wordpress plugins on the same install using log4php, loaded as explained in doc produce fatal error when used together:
> PHP Fatal error:  Cannot declare class LoggerAutoloader, because the name is already in use in /var/www/yyyyyyy.com/wp-content/plugins/myplugin/libs/log4php/2.3.0/LoggerAutoloader.php on line 34
> no change if include_once used instead of include



--
This message was sent by Atlassian Jira
(v8.3.4#803005)