List Info

Thread: Recommended usage for OO




Recommended usage for OO
user name
2007-07-20 19:33:28
Hi,

I am using Log4PHP for a project in PHP 5. I initialise it
in every class:

class B extends A{
  public $_logger;

  function __construct(...) {
    if (!$this->_logger) {
      $this->_logger =&
LoggerManager::getLogger(__CLASS__ . '.' .
get_class($this));
    }
    parent::__construct(...);
  }

This is fine, when I use virtual methods, but I cannot use
it in the
static methods. How do you use Log4PHP in your projects?

BTW. You have also some broken links at your page
htt
p://incubator.apache.org/projects/log4php.html
(Website link, Mailing list (un) subscribe links)


-- 
Ondra Medek

Re: Recommended usage for OO
user name
2007-07-22 15:15:03
Ondra Medek wrote:
> This is fine, when I use virtual methods, but I cannot
use it in the
> static methods. How do you use Log4PHP in your
projects?

Get the logger within the static method.

class B extends A {
  public static function someStaticFunction() {
    $debug = LoggerManager::getLogger('example');
  }
}

> BTW. You have also some broken links at your page
> htt
p://incubator.apache.org/projects/log4php.html
Thanks! 

Regards,
Knut Urdalen


Re: Recommended usage for OO
user name
2007-07-22 16:32:04
> class B extends A {
>   public static function someStaticFunction() {
>     $debug = LoggerManager::getLogger('example');
>   }
> }

yes, thanks, so is it better to do
LoggerManager::getLogger(...) in
each method (both, virtual and static), or may it be a
significant
performance decrease?

As far as I remember in Java, most of the people initialize
Log4J like:
public class MyClass {
   static Logger logger = Logger.getLogger(MyClass.class);
}
but it is not possible in PHP.

Re: Recommended usage for OO
user name
2007-07-23 08:35:15
>
> As far as I remember in Java, most of the people
initialize Log4J like:
> public class MyClass {
>   static Logger logger =
Logger.getLogger(MyClass.class);
> }
> but it is not possible in PHP.
>

Yes, You can.

<?php
class A {

    public static $logger;

}

A::$logger = LoggerManager::getLogger('A');
?>

Regards,
-Marco

Re: Recommended usage for OO
user name
2007-07-23 16:10:40
interesting,
thanks

On 7/24/07, Marco V. <marcoapache.org> wrote:
>
> >
> > As far as I remember in Java, most of the people
initialize Log4J like:
> > public class MyClass {
> >   static Logger logger =
Logger.getLogger(MyClass.class);
> > }
> > but it is not possible in PHP.
> >
>
> Yes, You can.
>
> <?php
> class A {
>
>     public static $logger;
>
> }
>
> A::$logger = LoggerManager::getLogger('A');
> ?>
>
> Regards,
> -Marco
>


-- 
Ondra Medek

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )