Completed
Push — master ( c52b32...efd649 )
by Oleksandr
01:35
created

isotopic_logging.IsotopicLogger   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 52.94%
Metric Value
dl 0
loc 25
ccs 9
cts 17
cp 0.5294
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A _get_proxy() 0 3 1
A __getattr__() 0 2 1
A static() 0 2 1
A direct() 0 2 1
A __init__() 0 2 1
A auto() 0 2 1
A hybrid() 0 2 1
1
# -*- coding: utf-8 -*-
2
3 1
from contextlib import contextmanager
4
5 1
from .context import (
6
    direct_injector, static_injector, auto_injector, hybrid_injector,
7
)
8 1
from .proxy import LoggerProxy
9
10
11 1
@contextmanager
12
def _get_proxy(logger, injector_context):
13
    with injector_context as injector:
14
        yield LoggerProxy(logger, injector)
15
16
17 1
class IsotopicLogger(object):
18
19 1
    __slots__ = ['_original', ]
20
21 1
    def __init__(self, logger):
22
        self._original = logger
23
24 1
    def __getattr__(self, name):
25
        return getattr(self._original, name)
26
27 1
    def direct(self, *args, **kwargs):
28
        return self._get_proxy(direct_injector, *args, **kwargs)
29
30 1
    def static(self, *args, **kwargs):
31
        return self._get_proxy(static_injector, *args, **kwargs)
32
33 1
    def auto(self, *args, **kwargs):
34
        return self._get_proxy(auto_injector, *args, **kwargs)
35
36 1
    def hybrid(self, *args, **kwargs):
37
        return self._get_proxy(hybrid_injector, *args, **kwargs)
38
39 1
    def _get_proxy(self, context_factory, *args, **kwargs):
40
        context = context_factory(*args, **kwargs)
41
        return _get_proxy(self._original, context)
42