3
responses

Hi,

I am using NXLog to run a script via im_exec and the internal restart true feature which restarts my script when it ends.

The thing I'm noticing is that it's filling up the nxlog.log file with error conditions because the script stopped.
ERROR Module test got EOF, process exited?

The script is restarting deliberately so I don't need to know about these specific messages from this specific module.

How can I suppress error logging from a specific module?

Have a wonderful day!

NOTE: I was able to get it working a different way.

The solution involves executing a script on startup to get the initial useful data and send it to a log file. From there NXLog searches for that file and copies it to gateway.log. The input module im_file then reads that file which initiates the heartbeat. The way that im_file works is that it caches the file and won’t read from it again unless the file changes(modifying last modified doesn’t appear to count as a change). To that end I added logic that would periodically delete and re-copy the file. In this way im_file has a new file to read from, and thus send the heartbeat.

While NXLog logs when the new files are read, they are logged as WARNING, not ERROR, so you can set the LogLevel to ERROR

<Extension _filedelete>
    Module xm_fileop
    <Schedule>
        Every 25 sec
        <Exec>
            if file_exists('%GATEWAY%.log') file_remove('%GATEWAY%.log');
            if file_exists('%GATEWAY%') file_copy('%GATEWAY%', '%GATEWAY%.log');
        </Exec>
    </Schedule>
</Extension>

<Input ipGateway>
    Module  im_file
    PollInterval 60
    ReadFromLast false
    SavePos false
    File    '%GATEWAY%.log'
    <Exec>
        $gateway = $raw_event;
    </Exec>
</Input>

This is not meant to be some kind of groundbreaking discovery. I only post it here in case someone else ends up trying to figure out this requirement.

Hope this helps!

AskedJanuary 29, 2020 - 10:25pm

Answer (1)

Casey,

Unfortunately, I don't think you can delete or change the type of logging level depending on the module.

Comments (2)

  • casey1234's picture

    Hi Manuel,

    Can I use the exec block to rename a file?

    <Input ipGateway>
        Module  im_file
        ReadFromLast false
        SavePos false
        File    '%GATEWAY%'
        <Exec>
            $gateway = $raw_event;
        </Exec>
    </Input>
    

    It looks like it polls by default once a second to look for a new file and if it doesn't detect anything changing it will not put anything into the pipeline.
    Would I be able to use the exec block to touch or change the last modified date the file to make it appear like it changed, thus being picked up during the next poll, and then sending data down the pipeline?

    Thanks!

  • Zhengshi's picture
    (NXLog)

    I think OnEOF and file_rename() together may do what you are looking for.

    Something like this example from the manual:

    <Input app_logs_rotated>
        Module  im_file
        File    '/var/log/app/*.log'
        <OnEOF>
            <Exec>
                file_rename(file_name(),
                            file_name() + strftime(now(), '_%Y%m%dT%H%M%S'));
            </Exec>
            GraceTimeout  10
        </OnEOF>
    </Input>
    

    https://nxlog.co/documentation/nxlog-user-guide/log-rotation.html#processing_rotation_input