-
Notifications
You must be signed in to change notification settings - Fork 647
/
class_logger.py
62 lines (52 loc) · 2.24 KB
/
class_logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Licensed to Modin Development Team under one or more contributor license agreements.
# See the NOTICE file distributed with this work for additional information regarding
# copyright ownership. The Modin Development Team licenses this file to you under the
# Apache License, Version 2.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
"""
Module contains ``ClassLogger`` class.
``ClassLogger`` is used for adding logging to Modin classes and their subclasses.
"""
from typing import Dict, Optional
from .config import LogLevel
from .logger_decorator import enable_logging
class ClassLogger:
"""
Ensure all subclasses of the class being inherited are logged, too.
Notes
-----
This mixin must go first in class bases declaration to have the desired effect.
"""
_modin_logging_layer = "PANDAS-API"
@classmethod
def __init_subclass__(
cls,
modin_layer: Optional[str] = None,
class_name: Optional[str] = None,
log_level: LogLevel = LogLevel.INFO,
**kwargs: Dict,
) -> None:
"""
Apply logging decorator to all children of ``ClassLogger``.
Parameters
----------
modin_layer : str, default: "PANDAS-API"
Specified by the logger (e.g. PANDAS-API).
class_name : str, optional
The name of the class the decorator is being applied to.
Composed from the decorated class name if not specified.
log_level : LogLevel, default: LogLevel.INFO
The log level (LogLevel.INFO, LogLevel.DEBUG, LogLevel.WARNING, etc.).
**kwargs : dict
"""
modin_layer = modin_layer or cls._modin_logging_layer
super().__init_subclass__(**kwargs)
enable_logging(modin_layer, class_name, log_level)(cls)
cls._modin_logging_layer = modin_layer