Is there a simple way of echoing any and all output to the post window, so that it is also written to a specified text file? and if so, a way of turning this on and off?
You can. It’s less easy and there are pitfalls.
If you want to do this, you can override the core post
methods in String
. You can start with an extension like this:
+String {
postln {
// do my custom stuff
this.prPostln();
}
post {
// do my custom stuff
this.prPost();
}
prPostln {
_PostLine
^this.primitiveFailed
}
prPost {
_PostString
^this.primitiveFailed
}
}
If you e.g. added a file write to these, then your problem will be… sorta solved. This should get you MOST post messages. It will not capture messages from the Server, since these don’t go through post
. There are also some edge case places where primitives print directly to the standard out - you would not capture these either.
If you mainly care about your OWN code, and want something more like logging functionality, you can use the Log quark (Quarks.install("git@github.com:scztt/Log.quark.git")
.
Then you can do:
~log = File("~/Desktop/log.txt".standardizePath, "w");
Log(\test2).actions.add({
|item|
~log.write("[% - %] %\n".format(
item[\level],
item[\time],
item[\string]
));
~log.flush();
});
Log(\test2).error("Uh oh error");
Log(\test2).info("This is just some info");