1
このような私のコードは、他のプロジェクトからコピーするが、私は、JSONでログレベルフィールドを見つけていない理由を、詳細のコードを知らない:Logstashどのように(ログレベルを表示しないで)追加できますか?
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger logger = context.getLogger("ROOT");
if (enabled == null || enabled) {
if (logger.getAppender(APPENDER_NAME) == null) {
String destination = host + ":" + port;
try {
DestinationParser.parse(destination, AbstractLogstashTcpSocketAppender.DEFAULT_PORT);
} catch (RuntimeException e) {
throw new IllegalArgumentException("Invalid host and port : " + destination);
}
LogstashTcpSocketAppender appender = new LogstashTcpSocketAppender();
appender.setContext(context);
appender.addDestination(destination);
appender.setName(APPENDER_NAME);
LogstashEncoder encoder = new LogstashEncoder();
encoder.setCustomFields("{\"application_name\":\"" + applicationName + "\"}");
encoder.setContext(context);
appender.setEncoder(encoder);
appender.start();
encoder.start();
logger.addAppender(appender);
logger.setLevel(Level.ALL);
https://github.com/Dreampie/docker-elk使用はヘラジカを開始docker-compose up -d --build
が、logstash結果はログレベルが含まれていない、logstash codec:"json"
を使用します。
{
"_index": "logstash-2016.10.10",
"_type": "logs",
"_id": "AVetGEgU-dbBmx39fbyl",
"_score": null,
"_source": {
"message": "{\"@timestamp\":\"2016-10-10T13:33:24.998+08:00\",\"@version\":1,\"message\":\"Retrieving delivery for Consumer: tags=[{amq.ctag-qURSKFA3CagYtd7y9EDAFQ=springCloudBus.anonymous.QTc6psI8RbOJm5oNFurqHA}], channel=Cached Rabbit Channel: AMQChannel(amqp://[email protected]:5672/,1), conn: [email protected] Shared Rabbit Connection: [email protected] [delegate=amqp://[email protected]:5672/], acknowledgeMode=AUTO local queue size=0\",\"logger_name\":\"org.springframework.amqp.rabbit.listener.BlockingQueueConsumer\",\"thread_name\":\"springCloudBus.anonymous.QTc6psI8RbOJm5oNFurqHA-1\",\"level\":\"DEBUG\",\"level_value\":10000,\"LOG_LEVEL_PATTERN\":\"%5p\",\"level\":\"DEBUG\",\"application_name\":\"user-api-provider\"}",
"@version": "1",
"@timestamp": "2016-10-10T05:37:11.819Z",
"host": "192.168.60.228",
"port": 52196
},
"fields": {
"@timestamp": [
1476077831819
]
},
"sort": [
1476077831819
]
}
[ask]と[mcve]を参照してください。 – Mat