Logstash log4j configuration pipeline.id

I created an logstash input plugin in jruby and when I do an @logger.info("log entry"), I'd like it to have a pipeline.id in the logstash-plain.log as generated by log4j2. Since I have several pipelines it's nice to use the pipeline.id variable. I can configure an id in the configuration input block or use the internal @id, but is the pipeline.id exposed to the plugin and/or log4j2?

This question is a bit similar to

But since I wrote the plugin I can do @logger.info(@id). When I run logstash from the commandline and not as ubuntu service the @id does get printed as "main"

So the pipeline_id is not exposed to the plugin, but since it's part of the thread name, I can extract it from there. I can cut out the pipeline.id from between the [ and ], because the threadname is in the format

[pipeline.id]<plugin.name

For the configuration in log4j2.properties the threadname can be printed with %t, so it will look like this

appender.rolling.layout.pattern = [%d{ISO8601}][%-5p]%t %-.10000m%n

you can strip some of the threadname by using the format modifiers, like %-6t if you use 4 character pipeline id's.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.