It's been a while since I posted for the last time, but today I decided to start a new session in this blog: Bits. Here, I'm going to share short, but good and useful experiences to help other people, including myself [in the future]. To debut the new session, I will describe the steps I took to send messages from a Python script to Syslog and how to monitor those logs in macOS.
Well, Python (3.9) comes with the Syslog module, which handles the process of creating log entries and it is really simple and straightforward. For instance, the line below creates a critical Syslog message:
In my experience, I had to run Python in unbuffered mode passing the -u option to the interpreter. Then, to check log files, I noticed that macOS does not work with Syslog like other similar systems. It comes with the log utility that has some commands to work with logs. Using the stream command with the right parameters and filtering the Python process, I was able to see all logs coming in [almost] real-time when the script was executed (almost like in tail -f).