Skip to content

Commit

Permalink
refac,docs: logging: Update log record format
Browse files Browse the repository at this point in the history
- Change: Exclude the process name in sessions where multiprocessing
  is disabled.
- Change: Update the log record format docs.
  • Loading branch information
AnonymouX47 committed Jun 24, 2024
1 parent cdb625a commit b2ccfa7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
12 changes: 9 additions & 3 deletions docs/source/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,22 @@ A log record has the following format (``<`` *and* ``>`` *mark placeholders, the
* *pid*: The process ID of the session.
* *date* and *time*: System date and time at which the record was created, in the format ``%Y-%m-%d %H:%M:%S,<ms>``, where ``<ms>`` is in milliseconds.
* *level*: The level of the record, this indicates it's importance.
* *process* and *thread*: The names of the python process and thread that produced the record.
* *process*: The name of the python process that produced the record.

* Only present when the *logging level* is set to ``DEBUG``
(either by :option:`--debug` or :option:`--log-level=DEBUG`).
(either via :option:`--debug` or :option:`--log-level=DEBUG`) and multiprocessing
is enabled (either via :option:`--multi` or :confval:`multi`).

* *thread*: The name of the python thread that produced the record.

* Only present when the *logging level* is set to ``DEBUG``
(either via :option:`--debug` or :option:`--log-level=DEBUG`).

* *module*: The package submodule from which it originated, or "termvisage" for session-level logs.
* *function*: The function from which it originated.

* Only present when the *logging level* is set to ``DEBUG``
(either by :option:`--debug` or :option:`--log-level=DEBUG`).
(either via :option:`--debug` or :option:`--log-level=DEBUG`).

* *message*: The actual report describing the event that occurred.

Expand Down
34 changes: 18 additions & 16 deletions src/termvisage/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,30 @@ def init_log(args: argparse.Namespace) -> None:
elif VERBOSE or VERBOSE_LOG:
level = logging.INFO

if (
not (config_options.multi if args.multi is None else args.multi)
or args.cli
or (os.cpu_count() or 0) <= 2 # Avoid affecting overall system performance
or sys.platform in {"win32", "cygwin"}
):
MULTI = False
else:
try:
import multiprocessing.synchronize # noqa: F401
except ImportError:
MULTI = False
else:
MULTI = True

FORMAT = (
"({process}) ({asctime}) [{levelname}] "
+ ("{processName}: {threadName}: " if DEBUG else "")
+ ("{processName}: " if DEBUG and MULTI else "")
+ ("{threadName}: " if DEBUG else "")
+ "{name}: "
+ ("{funcName}: " if DEBUG else "")
+ "{message}"
)

logging.basicConfig(
handlers=(handler,),
format=FORMAT,
Expand All @@ -70,21 +87,6 @@ def init_log(args: argparse.Namespace) -> None:
_logger.info("Starting a new session")
_logger.info(f"Logging level set to {logging.getLevelName(level)}")

if (
not (config_options.multi if args.multi is None else args.multi)
or args.cli
or (os.cpu_count() or 0) <= 2 # Avoid affecting overall system performance
or sys.platform in {"win32", "cygwin"}
):
MULTI = False
else:
try:
import multiprocessing.synchronize # noqa: F401
except ImportError:
MULTI = False
else:
MULTI = True

if MULTI:
from . import logging_multi
from .logging_multi import process_multi_logs
Expand Down

0 comments on commit b2ccfa7

Please sign in to comment.