Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Unittests
on: [push]
jobs:
run:
run-unittests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
24 changes: 17 additions & 7 deletions usr/lib/python3/dist-packages/linuxmusterLinuxclient7/logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import traceback, re, sys, subprocess
import traceback, re, sys, subprocess, inspect
from enum import Enum
from linuxmusterLinuxclient7 import config

Expand Down Expand Up @@ -61,11 +61,11 @@ def exception(exception):
:param exception: The exception to log
:type exception: Exception
"""
error("=== An exception occurred ===")
error(str(exception))
_log(Level.ERROR, "=== An exception occurred ===")
_log(Level.ERROR, str(exception))
# Only use for debugging! This will cause ugly error dialogs in X11
#traceback.print_tb(exception.__traceback__)
error("=== end exception ===")
_log(Level.ERROR, "=== end exception ===")

def printLogs(compact=False,anonymize=False):
"""
Expand Down Expand Up @@ -128,6 +128,16 @@ def _log(level, message):
if level == Level.FATAL:
sys.stderr.write(message)

print("[{0}] {1}".format(level.name, message))
message = message.replace("'", "")
subprocess.call(["logger", "-t", "linuxmuster-linuxclient7", f"[{level.name}] {message}"])
try:
frame = inspect.stack()[2]
module = inspect.getmodule(frame[0])
moduleName = module.__name__.replace("linuxmusterLinuxclient7.", "")
moduleName = f"({moduleName})"
except:
# This happens e.g. when logging from interactive shell
moduleName = ""

logMessage = f"[{level.name}] {moduleName} {message}"

print(logMessage)
subprocess.call(["logger", "-t", "linuxmuster-linuxclient7", logMessage])
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ def test_forAllLevels(mockSubprocessCall):
logging.exception(Exception("exception"))

logs = _getLoggedLogs(mockSubprocessCall)
assert logs == ["[DEBUG] debug", "[INFO] info", "[WARNING] warning", "[ERROR] error", "[FATAL] fatal", "[ERROR] === An exception occurred ===", "[ERROR] exception", "[ERROR] === end exception ==="]
assert logs == [
"[DEBUG] (tests.test_logging) debug",
"[INFO] (tests.test_logging) info",
"[WARNING] (tests.test_logging) warning",
"[ERROR] (tests.test_logging) error",
"[FATAL] (tests.test_logging) fatal",
"[ERROR] (tests.test_logging) === An exception occurred ===",
"[ERROR] (tests.test_logging) exception",
"[ERROR] (tests.test_logging) === end exception ==="
]

@mock.patch("linuxmusterLinuxclient7.logging.print")
@mock.patch("linuxmusterLinuxclient7.logging.open")
Expand Down