Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import traceback, re, sys, subprocess, inspect
import traceback, re, sys, inspect, syslog
from enum import Enum
from linuxmusterLinuxclient7 import config

syslog.openlog("linuxmuster-linuxclient7")

class Level(Enum):
DEBUG = 0
INFO = 1
Expand Down Expand Up @@ -140,4 +142,4 @@ def _log(level, message):
logMessage = f"[{level.name}] {moduleName} {message}"

print(logMessage)
subprocess.call(["logger", "-t", "linuxmuster-linuxclient7", logMessage])
syslog.syslog(logMessage)
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
from .. import logging
import os

@mock.patch("subprocess.call")
def test_forAllLevels(mockSubprocessCall):
@mock.patch("syslog.syslog")
def test_forAllLevels(mockSyslog):
logging.debug("debug")
logging.info("info")
logging.warning("warning")
logging.error("error")
logging.fatal("fatal")
logging.exception(Exception("exception"))

logs = _getLoggedLogs(mockSubprocessCall)
logs = _getLoggedLogs(mockSyslog)
assert logs == [
"[DEBUG] (tests.test_logging) debug",
"[INFO] (tests.test_logging) info",
Expand All @@ -24,12 +24,12 @@ def test_forAllLevels(mockSubprocessCall):
]

@mock.patch("inspect.stack")
@mock.patch("subprocess.call")
def test_inspectStackEmpty(mockSubprocessCall, mockInspectStack):
@mock.patch("syslog.syslog")
def test_inspectStackEmpty(mockSyslog, mockInspectStack):
mockInspectStack.return_value = []
logging.info("info without module name")

logs = _getLoggedLogs(mockSubprocessCall)
logs = _getLoggedLogs(mockSyslog)
assert logs == [
"[INFO] info without module name"
]
Expand All @@ -56,14 +56,8 @@ def test_printLogs(mockConfigNetwork, mockOpen, mockPrint):
# - Helper functions -
# --------------------

def _getLoggedLogs(mockSubprocessCall):
logs = []
for call_args in mockSubprocessCall.call_args_list:
args = call_args.args[0]
print(args)
if type(args) == list and args[0] == "logger":
logs.append(args[3])
return logs
def _getLoggedLogs(mockSyslog):
return [call_args.args[0] for call_args in mockSyslog.call_args_list]

def _getPrintedLines(mockPrint):
lines = []
Expand Down
Loading