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

isotopic_logging._get_proxy()   A

Complexity

Conditions 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3.1854
Metric Value
cc 2
dl 0
loc 4
ccs 1
cts 3
cp 0.3333
crap 3.1854
rs 10
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