kquick / Thespian

Python Actor concurrency library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Centralised logging

cl-dev opened this issue · comments

Hi,

Thespian's documentation states that it's possible to send logging messages to a central actor. Is this functionality available out of the box?

I'm finding it very difficult to reliably produce logs in my application. The scenario is as follows:

  • One python application instantiates the Actor System (TCP Base), creates one actor and then sends it messages (using tell) forever (i.e. until de application is closed);
  • This application also sets the logging basicConfig, specifying a filename and a level (DEBUG);
  • A second python application does the same as the one described above, but it only starts after the first is ready, with a 30 sec separation;
  • A third application instantiates 3 other actors and then waits for a keystroke before exiting.

Oddly enough, the first two applications successfully write their logs, each to its own file. The third application produces the log file but it stays empty. The logs end up showing, in red, on the first application's shell.

Also, Thespian completely ignores the THESPLOG_FILE environment variable, so there's no way to find out what's wrong under the bonnet.

Lastly, the application as a whole (the 5 actors + their offspring) runs fine.

Any ideas?

Thanks.

The centralized logging capability is available "out of the box" in the standard Thespian distribution. When running a multiproc base (such as the multiprocTCPBase that you are using) you can observe both a MultiProcAdmin and a logger actor are created; the latter will handle the logging specified by the logDefs argument to the ActorSystem().

One aspect that might be causing you difficulty is that the first ActorSystem call starts up the MultiProcAdmin and logger processes and logging cannot be changed after that point. Both of those processes are long-lived until you issue an ActorSystem().shutdown() call to stop them. Thus the logging characteristics are probably dependent on which of your three applications you start first; logging appearing on stdout/stderr of one of your shells probably indicates that the ActorSystem was started by that shell and that the logging configuration at the time was not directed to an output file so it defaulted (to stderr).

The THESPLOG_FILE environment variable should be honored, but there is a corresponding THESPLOG_THRESHOLD that you probably want to set; the default of WARNING means you probably won't see much in the file. This file will log mostly internals that are hard to interpret without intimate knowledge of the source code, but in the event that we need to dig into this issue further they may be helpful for me to evaluate what's going wrong. Here's where the THESPLOG_FILE is utilized, FYI: https://github.com/kquick/Thespian/blob/master/thespian/system/utilis.py#L76

And thanks for your "lastly" note: it's nice to know things are generally working as they should! :-)

Hi,

As usual, your analysis is spot on. I was indeed configuring the logger more than once, which caused the odd behaviour. Fixing this solved the issue and my application now produces one single log file, just as intended.

Regarding my "lastly" note, I think it's important to be thankful for the hard work of others, especially if I benefited from it in some way. Your actor model library saved me a lot of time and made my application more robust overall.

Thanks and keep up the good work!