3
responses

Hello all,

I'm trying out NXLog to do some basic log file rotation. I'm just looking for it to rotate a specifed log file when it gets past 100K. For a PoC I've set up my nxlog.conf as follows, but no logs are ever rotated nor do any of the log_info calls ever get into the nxlog.log. Can someone help me with what I'm trying to accomplish? Thanks.

define TESTLOG 'C:\Logs\testlog.log'
<Extension fileop>
Module xm_fileop
</Extension>

<Input logrotatein>
Module im_file
File "%TESTLOG%"
</Input>

<Output logrotateout>
Module om_file
File %TESTLOG%

<Schedule>
Every 30 seconds
log_info('I am doing something');
Exec if (file_size('%TESTLOG%') >= 100K)
{
log_info('I am rotating');
file_cycle('%TESTLOG%',500);
logrotate->reopen();
}
</Schedule>
</Output>

<Route 1>
Path logrotatein => logrotateout
</Route>

AskedMarch 12, 2018 - 7:34pm

Answer (1)

The define configuration option is simply a string replacement operation.

define TESTLOG 'C:\Logs\testlog.log'
Exec if (file_size('%TESTLOG%') >= 100K)

The above yields this:

Exec if (file_size(''%TESTLOG%'') >= 100K)

Also logrotate->reopen(); references a module instance that does not exist. There are missing line terminators.

I don't think this would work at all without any configuration errors in nxlog.log...

Comments (2)

  • mdemougin's picture

    Ok, I dramatically changed the config file and it's pretty much working, but is there a way to define the chunking size? I didn't find anything in the documentation.

    Something like
    Every 1 min
    file_cycle(%TESTLOG%, MAXSIZE) where it rotates off a specific amount each time?

    or

    Every time it gets to X Size
    file_cycle(%TESTLOG%);

    Here's my current conf file:

    define ROOT C:\Program Files (x86)\nxlog
    define TESTLOG 'C:\Logs\testlog.txt'
    LogFile C:\Logs\nx.log
    Moduledir %ROOT%\modules
    CacheDir %ROOT%\data
    Pidfile %ROOT%\data\nxlog.pid

    <Extension fileop>
    Module xm_fileop
    <Schedule>
    Every 1 min
    Exec if (file_size(%TESTLOG%) >= 100K) file_cycle(%TESTLOG%, 200);
    </Schedule>
    </Extension>