• syslog problem

    From ft@ml@ft-c.de to muc.lists.freebsd.stable on Sat Feb 14 18:55:53 2026
    From Newsgroup: muc.lists.freebsd.stable

    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.
    =====
    #!/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)
    LOG_E("test_e23")
    # print("test_e23")
    # time.sleep(1)
    LOG_E("test_e33")
    # print("test_e33")
    # time.sleep(1)
    LOG_E("test_e43")
    # print("test_e43")
    # time.sleep(1)
    LOG_E("test_e53")
    # print("test_e53")
    # time.sleep(1)
    LOG_E("test_e63")
    # print("test_e63")
    # time.sleep(1)
    LOG_E("test_e73")
    # print("test_e73")
    # time.sleep(1)
    --
    Posted automagically by a mail2news gateway at muc.de e.V.
    Please direct questions, flames, donations, etc. to news-admin@muc.de
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Miroslav Lachman@000.fbsd@quip.cz to muc.lists.freebsd.stable on Sat Feb 14 19:42:07 2026
    From Newsgroup: muc.lists.freebsd.stable

    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)

    [...]


    --
    Posted automagically by a mail2news gateway at muc.de e.V.
    Please direct questions, flames, donations, etc. to news-admin@muc.de
    --- Synchronet 3.21b-Linux NewsLink 1.2