aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2025-08-15 21:39:34 +0100
committerTomasz Kramkowski <tomasz@kramkow.ski>2025-08-15 21:46:37 +0100
commit2e957a0efca9ca8f029b7787ba7ebafb2b5aa56a (patch)
treeebacf45d39539dcfe6e171561a101e4bf210a699
parent5cc72c0da7043af9fa5b72af60a701d0162ea82a (diff)
downloadkutter-2e957a0efca9ca8f029b7787ba7ebafb2b5aa56a.tar.gz
kutter-2e957a0efca9ca8f029b7787ba7ebafb2b5aa56a.tar.xz
kutter-2e957a0efca9ca8f029b7787ba7ebafb2b5aa56a.zip
Remove logfile support
-rw-r--r--CHANGELOG.md1
-rw-r--r--docs/API_Server.md2
-rw-r--r--klippy/configfile.py9
-rw-r--r--klippy/extras/bed_tilt.py1
-rw-r--r--klippy/kinematics/extruder.py1
-rw-r--r--klippy/klippy.py21
-rw-r--r--klippy/mcu.py2
-rw-r--r--klippy/queuelogger.py35
-rw-r--r--klippy/toolhead.py1
-rw-r--r--klippy/webhooks.py8
-rw-r--r--scripts/test_klippy.py16
11 files changed, 11 insertions, 86 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a1073193..ea439680 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,3 +37,4 @@ Most changes are breaking.
* Init script
* The `make_version.py` script
* Linux "flash" script
+* Log file support (now always configured to log to stderr)
diff --git a/docs/API_Server.md b/docs/API_Server.md
index 01d33023..92eb2409 100644
--- a/docs/API_Server.md
+++ b/docs/API_Server.md
@@ -56,7 +56,7 @@ and a response might look like:
"/home/pi/printer.cfg", "software_version": "v0.8.0-823-g883b1cb6",
"hostname": "octopi", "cpu_info": "4 core ARMv7 Processor rev 4
(v7l)", "state": "ready", "python_path":
-"/home/pi/klippy-env/bin/python", "log_file": "/tmp/klippy.log"}}`
+"/home/pi/klippy-env/bin/python"}}`
Each request must be a JSON dictionary. (This document uses the Python
term "dictionary" to describe a "JSON object" - a mapping of key/value
diff --git a/klippy/configfile.py b/klippy/configfile.py
index c3a21d7d..6860a964 100644
--- a/klippy/configfile.py
+++ b/klippy/configfile.py
@@ -552,15 +552,6 @@ class PrinterConfig:
self._build_status_config(config)
return config
- def log_config(self, config):
- cfgrdr = ConfigFileReader()
- lines = [
- "===== Config file =====",
- cfgrdr.build_config_string(config.fileconfig),
- "=======================",
- ]
- self.printer.set_rollover_info("config", "\n".join(lines))
-
def check_unused_options(self, config):
self.validate.check_unused(config.fileconfig)
diff --git a/klippy/extras/bed_tilt.py b/klippy/extras/bed_tilt.py
index 54bdce56..1bbce154 100644
--- a/klippy/extras/bed_tilt.py
+++ b/klippy/extras/bed_tilt.py
@@ -116,7 +116,6 @@ class BedTiltCalibrate:
y_adjust,
z_adjust,
)
- self.printer.set_rollover_info("bed_tilt", "bed_tilt: %s" % (msg,))
self.gcode.respond_info(
"%s\nThe above parameters have been applied to the current\n"
"session. The SAVE_CONFIG command will update the printer\n"
diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py
index 25ac394d..ae1604db 100644
--- a/klippy/kinematics/extruder.py
+++ b/klippy/kinematics/extruder.py
@@ -132,7 +132,6 @@ class ExtruderStepper:
pressure_advance,
smooth_time,
)
- self.printer.set_rollover_info(self.name, "%s: %s" % (self.name, msg))
gcmd.respond_info(msg, log=False)
cmd_SET_E_ROTATION_DISTANCE_help = "Set extruder rotation distance"
diff --git a/klippy/klippy.py b/klippy/klippy.py
index fbb2e0d3..c1821b13 100644
--- a/klippy/klippy.py
+++ b/klippy/klippy.py
@@ -128,8 +128,6 @@ class Printer:
def _read_config(self):
self.objects["configfile"] = pconfig = configfile.PrinterConfig(self)
config = pconfig.read_main_config()
- if self.bglogger is not None:
- pconfig.log_config(config)
# Create printer components
for m in [pins, mcu]:
m.add_printer_objects(config)
@@ -217,12 +215,6 @@ class Printer:
logging.exception("Unhandled exception during post run")
return run_result
- def set_rollover_info(self, name, info, log=True):
- if log:
- logging.info(info)
- if self.bglogger is not None:
- self.bglogger.set_rollover_info(name, info)
-
def invoke_shutdown(self, msg, details={}):
if self.in_shutdown_state:
return
@@ -314,9 +306,6 @@ def main():
help="path to where SAVE_CONFIG should store the runtime configuration",
)
opts.add_option(
- "-l", "--logfile", dest="logfile", help="write log to file instead of stderr"
- )
- opts.add_option(
"-v", action="store_true", dest="verbose", help="enable debug messages"
)
opts.add_option(
@@ -360,12 +349,7 @@ def main():
if options.debugoutput:
start_args["debugoutput"] = options.debugoutput
start_args.update(options.dictionary)
- bglogger = None
- if options.logfile:
- start_args["log_file"] = options.logfile
- bglogger = queuelogger.setup_bg_logging(options.logfile, debuglevel)
- else:
- logging.getLogger().setLevel(debuglevel)
+ bglogger = queuelogger.setup_bg_logging(debuglevel)
logging.info("Starting Klippy...")
start_args["software_version"] = __version__
start_args["cpu_info"] = util.get_cpu_info()
@@ -386,9 +370,6 @@ def main():
# Start Printer() class
while 1:
- if bglogger is not None:
- bglogger.clear_rollover_info()
- bglogger.set_rollover_info("versions", versions)
gc.collect()
main_reactor = reactor.Reactor(gc_checking=True)
printer = Printer(main_reactor, bglogger, start_args)
diff --git a/klippy/mcu.py b/klippy/mcu.py
index a4506938..635128f4 100644
--- a/klippy/mcu.py
+++ b/klippy/mcu.py
@@ -961,8 +961,6 @@ class MCU:
# Log config information
move_msg = "Configured MCU '%s' (%d moves)" % (self._name, move_count)
logging.info(move_msg)
- log_info = self._log_info() + "\n" + move_msg
- self._printer.set_rollover_info(self._name, log_info, log=False)
def _mcu_identify(self):
if self.is_fileoutput():
diff --git a/klippy/queuelogger.py b/klippy/queuelogger.py
index b5bfc612..2792d513 100644
--- a/klippy/queuelogger.py
+++ b/klippy/queuelogger.py
@@ -22,20 +22,16 @@ class QueueHandler(logging.Handler):
except Exception:
self.handleError(record)
-
# Class to poll a queue in a background thread and log each message
-class QueueListener(logging.handlers.TimedRotatingFileHandler):
- def __init__(self, filename):
- logging.handlers.TimedRotatingFileHandler.__init__(
- self, filename, when="midnight", backupCount=5
- )
+class QueueListener(logging.StreamHandler):
+ def __init__(self):
+ super().__init__()
self.bg_queue = queue.Queue()
self.bg_thread = threading.Thread(target=self._bg_thread)
self.bg_thread.start()
- self.rollover_info = {}
def _bg_thread(self):
- while 1:
+ while True:
record = self.bg_queue.get(True)
if record is None:
break
@@ -45,32 +41,13 @@ class QueueListener(logging.handlers.TimedRotatingFileHandler):
self.bg_queue.put_nowait(None)
self.bg_thread.join()
- def set_rollover_info(self, name, info):
- if info is None:
- self.rollover_info.pop(name, None)
- return
- self.rollover_info[name] = info
-
- def clear_rollover_info(self):
- self.rollover_info.clear()
-
- def doRollover(self):
- logging.handlers.TimedRotatingFileHandler.doRollover(self)
- lines = [self.rollover_info[name] for name in sorted(self.rollover_info)]
- lines.append(
- "=============== Log rollover at %s ===============" % (time.asctime(),)
- )
- self.emit(
- logging.makeLogRecord({"msg": "\n".join(lines), "level": logging.INFO})
- )
-
MainQueueHandler = None
-def setup_bg_logging(filename, debuglevel):
+def setup_bg_logging(debuglevel):
global MainQueueHandler
- ql = QueueListener(filename)
+ ql = QueueListener()
MainQueueHandler = QueueHandler(ql.bg_queue)
root = logging.getLogger()
root.addHandler(MainQueueHandler)
diff --git a/klippy/toolhead.py b/klippy/toolhead.py
index 13ef7e2b..c0693d6f 100644
--- a/klippy/toolhead.py
+++ b/klippy/toolhead.py
@@ -832,7 +832,6 @@ class ToolHead:
self.square_corner_velocity,
)
)
- self.printer.set_rollover_info("toolhead", "toolhead: %s" % (msg,))
if (
max_velocity is None
and max_accel is None
diff --git a/klippy/webhooks.py b/klippy/webhooks.py
index 76ef502d..21181e45 100644
--- a/klippy/webhooks.py
+++ b/klippy/webhooks.py
@@ -208,12 +208,6 @@ class ClientConnection:
if state_msg is None:
state_msg = "Client info %s" % (repr(client_info),)
logging.info("webhooks client %s: %s", self.uid, state_msg)
- log_id = "webhooks %s" % (self.uid,)
- if client_info is None:
- self.printer.set_rollover_info(log_id, None, log=False)
- return
- rollover_msg = "webhooks client %s: %s" % (self.uid, repr(client_info))
- self.printer.set_rollover_info(log_id, rollover_msg, log=False)
def close(self):
if self.fd_handle is None:
@@ -375,7 +369,7 @@ class WebHooks:
"group_id": os.getgid(),
}
start_args = self.printer.get_start_args()
- for sa in ["log_file", "config_file", "software_version", "cpu_info"]:
+ for sa in ["config_file", "software_version", "cpu_info"]:
response[sa] = start_args.get(sa)
web_request.send(response)
diff --git a/scripts/test_klippy.py b/scripts/test_klippy.py
index 93ea2f34..de7ce757 100644
--- a/scripts/test_klippy.py
+++ b/scripts/test_klippy.py
@@ -6,7 +6,6 @@
import sys, os, optparse, logging, subprocess
TEMP_GCODE_FILE = "_test_.gcode"
-TEMP_LOG_FILE = "_test_.log"
TEMP_OUTPUT_FILE = "_test_output"
@@ -109,13 +108,9 @@ class TestCase:
]
for df in dict_fnames:
args += ["-d", df]
- if not self.verbose:
- args += ["-l", TEMP_LOG_FILE]
res = subprocess.call(args)
is_fail = (should_fail and not res) or (not should_fail and res)
if is_fail:
- if not self.verbose:
- self.show_log()
if should_fail:
raise error("Test failed to raise an error")
raise error("Error during test")
@@ -125,10 +120,7 @@ class TestCase:
for fname in os.listdir(self.tempdir):
if fname.startswith(TEMP_OUTPUT_FILE):
os.unlink(fname)
- if not self.verbose:
- os.unlink(TEMP_LOG_FILE)
- else:
- sys.stderr.write("\n")
+ sys.stderr.write("\n")
if gcode_is_temp:
os.unlink(gcode_fname)
@@ -142,12 +134,6 @@ class TestCase:
return "internal error"
return "success"
- def show_log(self):
- f = open(TEMP_LOG_FILE, "r")
- data = f.read()
- f.close()
- sys.stdout.write(data)
-
######################################################################
# Startup