Re: syslog problem

Miroslav Lachman <[email protected]>
Newsgroups gmane.os.freebsd.stable
Message-ID <[email protected]>
On 14/02/2026 18:55, ft wrote:
> Hello,
> 
> I have a Python script that writes messages to syslog.
> 
> The script works with the print and sleep commands. When I remove the
> print and sleep commands, only the first two commands appear in
> local5.log file.

Well I think the problem is in the fast repetition of openlog + 
closelog. The messages may be buffered or discarded by some rate 
limiting. If you remove syslog.closelog() from the LOG_E function and 
put it at the end of the script, all messages are logged, because syslog 
receive them in one connection.

Best regards
Miroslav Lachman

> =====
> #!/usr/bin/env python3.14
> 
> import syslog
> import os
> import sys
> import time
> 
> FACILITY = syslog.LOG_LOCAL5
> 
> def _get_script_name():
>      return os.path.basename(sys.argv[0])
> 
> 
> def LOG_E(message):
>      script_name = _get_script_name()
>      formatted_message = f"ERROR: {script_name} {message}"
>      syslog.openlog(
>          ident=script_name,
>          logoption=syslog.LOG_PID,
>          facility=FACILITY
>      )
>      syslog.syslog(syslog.LOG_INFO, formatted_message)
>      syslog.closelog()
> 
> 
> LOG_E("test_e13aaa")
> # print("test_e13")
> # time.sleep(1)
> 
[...]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.