-
Notifications
You must be signed in to change notification settings - Fork 52
/
utils.py
47 lines (33 loc) · 1.11 KB
/
utils.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
"""oct2py general utils."""
# Copyright (c) oct2py developers.
# Distributed under the terms of the MIT License.
from __future__ import annotations
import logging
import sys
class Oct2PyError(Exception):
"""Called when we can't open Octave or Octave throws an error"""
pass
def get_log(name: str | None = None) -> logging.Logger:
"""Return a console logger.
Output may be sent to the logger using the `debug`, `info`, `warning`,
`error` and `critical` methods.
Parameters
----------
name : str
Name of the log.
"""
name = "oct2py" if name is None else "oct2py." + name
log = logging.getLogger(name)
log.setLevel(logging.INFO)
return log
def _setup_log() -> None:
"""Configure root logger."""
try:
handler = logging.StreamHandler(stream=sys.stdout)
except TypeError: # pragma: no cover
handler = logging.StreamHandler(strm=sys.stdout) # type:ignore[call-overload]
log = get_log()
log.addHandler(handler)
log.setLevel(logging.INFO)
log.propagate = False
_setup_log()