On Wed, Mar 06, 2013 at 02:08:24PM +0900, YAMAMOTO Takashi wrote:
> > How about logging.LoggerAdapter?
> > I'm not sure it provides format you want, you can inherit it
> > if you need.
> 
> do you mean something like this?

Exactly.


> YAMAMOTO Takashi
> 
> 
> commit 6d8f5ee3d3085087528b39813c722d5e2ae8e0cb
> Author: YAMAMOTO Takashi <[email protected]>
> Date:   Wed Mar 6 14:05:44 2013 +0900
> 
>     plogger: simplify using LoggerAdapter
>     
>     Signed-off-by: YAMAMOTO Takashi <[email protected]>
> 
> diff --git a/ryu/plogger.py b/ryu/plogger.py
> index c95a461..7204d43 100644
> --- a/ryu/plogger.py
> +++ b/ryu/plogger.py
> @@ -15,17 +15,13 @@
>  # limitations under the License.
>  
>  
> -class PrefixedLogger(object):
> -    def __init__(self, logger, prefix):
> -        self.logger = logger
> -        self.prefix = prefix
> +import logging
> +
>  
> -    def __getattr__(self, name):
> -        basemethod = getattr(self.logger, name)
> -        if not name in ['debug', 'info', 'warn', 'error', 'critical',
> -                        'exception']:
> -            raise AttributeError
> +class PrefixedLogger(logging.LoggerAdapter):
> +    def __init__(self, logger, prefix):
> +        logging.LoggerAdapter.__init__(self, logger, {})
> +        self.__prefix = prefix
>  
> -        def method(msg, *args, **kwargs):
> -            return basemethod("%s %s" % (self.prefix, msg), *args, **kwargs)
> -        return method
> +    def process(self, msg, kwargs):
> +        return ("%s %s" % (self.__prefix, msg), kwargs)
> 

-- 
yamahata

------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to