3
responses

Hi there,

I have several hosts where lots of logs are generated. On every of this hosts logs are placed into one directory and have different names with *.log extension. My point is to use nxlog on that hosts to forward logs into one central storage but I have problem with populating files names. I would like that file source/first.log to be populated to destination/first.log. Similarly source/second.log -> destination/second.log etc. Below is my config file.

Moduledir %ROOT%\modules
CacheDir %ROOT%\data
Pidfile %ROOT%\data\nxlog.pid
SpoolDir %ROOT%\data
LogFile %ROOT%\data\nxlog.log

define LOG_SERVER \\\\192.168.199.10

<Extension _syslog>
    Module      xm_syslog
</Extension>

<Input app-logs>
    Module im_file
    File "d:\\Logs\\\\*.log"
    InputType LineBased    
    <Schedule>
        Every 30 sec
        Exec log_info("scheduled execution at " + now());
    </Schedule>    
    Exec $fileName = file_name();
</Input>

<Output out>    
    Module om_file
    CreateDir TRUE        
    File "%LOG_SERVER%\\Shared\\Logs\\" + $fileName
</Output>

<Route 1>
    Path        app-logs => out
</Route>

Logs are not populating and I have in nxlog logs something like that

2015-11-20 15:11:00 ERROR CreateDir is TRUE but couldn't create directory: \\192.168.199.10\Shared\Logs\d:\Logs\; The specified path is invalid.  

Will be gratefull for help with my issue.

 

AskedNovember 20, 2015 - 3:13pm

Answer (1)

I believe this is what you want since file_name() returns the full path which is giving the errors.

Exec $fileName = file_basename(file_name());

Comments (2)

  • leshqo's picture

    Thanks for the answer. I've updated my config and it looks now as below.

    <Extension _syslog> 
        Module      xm_fileop
    </Extension>
    
    <Input app-logs>
        Module im_file
        File "d:\\Logs\\\\*.log"
        InputType LineBased 
        <Schedule>
            Every 5 sec
            Exec log_info("scheduled execution at " + now());
        </Schedule>
        #PollInterval 30 
        SavePos TRUE
        Exec $fileName = file_basename(file_name());
    </Input>
    
    <Output out> 
        Module om_file
        CreateDir TRUE 
        File "%LOG_SERVER%\\Shared\\Logs\\" + $fileName
    </Output>
    
    <Route 1>
        Path        app-logs => out
    </Route>

    But sill receiving error, suggested that $fileName is empty

    2015-11-20 17:21:30 ERROR failed to open \\192.168.199.10\Shared\Logs\; The filename, directory name, or volume label syntax is incorrect.