Reputation: 315
I have read different articles about centralized logging. Most of them seems to use Redis as Brocker and logstash shipper to write to it.
Is it possible to write directly to Redis from a Java web application ? Without logging to a file and then have logstash reading the file and sending the event to Redis. Or is it considered bad practice ?
Since logstash is written in Java, maybe there is even a way to use its Redis output ?
Upvotes: 1
Views: 1492
Reputation: 7890
First, logstash plugin is write in Ruby, not Java!
Of course, you can send the logs to redis directly!
For example, this is my logstash indexer configuration. My redis data_type is list
and key is logstash
input {
redis {
port => 5566
data_type => "list"
key => "logstash"
}
}
output {
stdout {
codec => rubydebug
}
}
I start a redis server on the port 5566, and then logstash indexer read the logs directly from redis.
When I use redis-cli
to put a log to the logstash
list,
redis 127.0.0.1:5566> lpush logstash "abc"
Logstash can read the logs from redis and create a log event. The logstash output is:
{
"message" => "abc",
"@version" => "1",
"@timestamp" => "2014-07-09T01:16:33.566Z"
}
And also, you can refer to here about how to implement the redis-cli. For example, use jredis as your client in JAVA and send the log directly to logstash list in redis.
Have fun and try it. If you have any problem, please feel free to ask! :)
Upvotes: 2