Papertrail recommends nxlog as their Windows log management tool of choice, so that's what I used. This Papertrail article explains how to install and configure nxlog on Windows (I recommend enabling TLS). The nxlog.conf template file provided by Papertrail will send Windows Event logs over. I also wanted to send application-specific logs, so here's what I did:
1) Add an Input section to nxlog.conf for each directory containing the files you want to send to Papertrail. For example, if one of your applications logs to C:\MyApp1\logs and your log files end with .log, you could have this input section:
# Monitor MyApp1 log files
START_ANGLE_BRACKET Input MyApp1 END_ANGLE_BRACKET
Module im_file
File 'C:\\MyApp1\\logs\\*.log'
Exec $Message = $raw_event;
Exec if $Message =~ /GET \/ping/ drop();
Exec if file_name() =~ /.*\\(.*)/ $SourceName = $1;
SavePos TRUE
Recursive TRUE
START_ANGLE_BRACKET /Input END_ANGLE_BRACKET
Some observations:
- Blogger doesn't like angle brackets so replace START_ANGLE_BRACKET with < and END_ANGLE_BRACKET with >
- The name MyApp1 is the name of this Input section
- The File statement points to the location and name of the log files
- The first Exec statement saves the log line under consideration as the variable $Message
- The second Exec statement drops messages that contain a specific regular expression, in my case just 'GET /ping' -- which happens to be health checks from the load balancer that pollute the logs; you can replace this with any regular expression that will filter out log lines you don't want sent to Papertrail
- The next few statements were in the sample Input stanza from the template nxlog.conf file so I just left them there
2) Add more Input sections, one for each log location (i.e. multiple log files under a given directory) that you want to send to Papertrail. You need to give each Input section a unique name (e.g. MyApp1 above).
3) Add a Route section for the Input sections defined previously. If you defined 2 Input sections MyApp1 and MyApp2, your Route section would look something like:
START_ANGLE_BRACKET Route 2 END_ANGLE_BRACKET
Path MyApp1, MyApp2=> filewatcher_transformer => syslogout
Path MyApp1, MyApp2=> filewatcher_transformer => syslogout
START_ANGLE_BRACKET /Route END_ANGLE_BRACKET
The filewatcher_transformer section was already included in the sample nxlog.conf file from Papertrail. The Route section above says that the files processed by the 2 Input paths MyApp1 and MyApp2 will be processed through the statements defined in the filewatcher_transformer section, then will be sent to Papertrail by virtue of being processed through the statements defined in the syslogout section.
At this point, if you restart the nxlog service on your Windows box, you should start seeing log entries from your application(s) flowing into the Papertrail console.
No comments:
Post a Comment