API¶
- class log_decor.add_logger(name=None)¶
Add logger to class.
The logger will be saved in an attribute named ‘logger’.
- Parameters:
name (
Optional
[str
]) – Name of logger. If not given, the name of the class is used.- Return type:
Callable
[[TypeVar
(Class
)],Type
[TypeVar
(Class
)]]
- class log_decor.log_func(msg=None, level=10, arg_func=None, res_func=None)¶
Add logging functionality to function|method.
Applies a function (arg_func) to the args|kwargs and other function (res_func) to the result before logging. The format of the message is:
message(arg_func_result) -> res_func_result
- Parameters:
msg (
Optional
[str
]) – Start of log message. If not given, the name of the function|method is used.level (
Optional
[int
]) – Log level. Default is DEBUG.arg_func (
Optional
[Callable
[...
,str
]]) – Function to apply to args|kwargs. If not given, a function that returns an empty string is used.res_func (
Optional
[Callable
[...
,str
]]) – Function to apply to result. If not given, a function that returns an empty string is used.
- Return type:
Callable
[[Union
[Callable
[[ParamSpec
(Param
)],TypeVar
(RetType
)],Callable
[[Concatenate
[Type
[Class
],ParamSpec
(Param
)]],TypeVar
(RetType
)]]],Union
[Callable
[[ParamSpec
(Param
)],TypeVar
(RetType
)],Callable
[[Concatenate
[Type
[Class
],ParamSpec
(Param
)]],TypeVar
(RetType
)]]]
- class log_decor.log_info(level=10)¶
Add logging functionality to function|method.
Logs the args|kwargs, time duration of execution, and result. The format of the message is:
function_name(args|kwargs) [0-9*.0-9*s] -> result
- Parameters:
level (
Optional
[int
]) – Log level. Default is DEBUG.- Return type:
Callable
[[Union
[Callable
[[ParamSpec
(Param
)],TypeVar
(RetType
)],Callable
[[Concatenate
[Type
[Class
],ParamSpec
(Param
)]],TypeVar
(RetType
)]]],Union
[Callable
[[ParamSpec
(Param
)],TypeVar
(RetType
)],Callable
[[Concatenate
[Type
[Class
],ParamSpec
(Param
)]],TypeVar
(RetType
)]]]
- class log_decor.log_msg(msg=None, level=10)¶
Add logging functionality to function|method.
Logs given message. The format of the log message is:
given_message
- Parameters:
msg (
Optional
[str
]) – Message to log. Default is ‘function_name()’.level (
Optional
[int
]) – Log level. Default is DEBUG.
- Return type:
Callable
[[Union
[Callable
[[ParamSpec
(Param
)],TypeVar
(RetType
)],Callable
[[Concatenate
[Type
[Class
],ParamSpec
(Param
)]],TypeVar
(RetType
)]]],Union
[Callable
[[ParamSpec
(Param
)],TypeVar
(RetType
)],Callable
[[Concatenate
[Type
[Class
],ParamSpec
(Param
)]],TypeVar
(RetType
)]]]