I need a logging library for my multi-threaded Tcl aplication. Can I use standard logger package? If I can, what restrictions are applied in multi-threading environment?
I’d like to share logging services among the threads, if possible.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Tcl threads do not share data (unless you explicitly use certain facilities from the Thread package) and instead are communicating via message passing. So it seems like the way to go would be to setup a dedicated “logger” thread and just queue logging messages into it from the worker threads.
Otherwise the point of contention will probably be somewhere in the OS resource used by the logger to actually write data.
Update Okay, here’s a working sketch of what I actually proposed to implement:
This code creates one logger thread and four worker threads each of which posts a message to the logger thread once per second. The code runs until manually interrupted. The logger thread just simple-mindedly outputs the message it was passed to the console, but as someone else in this thread already mentioned, you could probably use the “logger” package from Tcllib, if you need fancy stuff like facilities.
To reiterate my points:
P.S. In the worker threads, you can use
[thread::send -async ...]to make sending log messages fully asynchronous.