使用Java应用程序中的Logback配置发送到控制台的日志,使用Kubectl日志在Kubernetes中不可见 [英] Logs sent to console using logback configuration in java app, not visible in Kubernetes using kubectl logs
问题描述
我在kubernetes文档中的某个地方读取了kubernetes文档,该文档从pod中的stdout和stderror读取应用程序日志. 我创建了一个新应用程序,并将其配置为将日志发送到远程splunk hec端点(使用splunk-logback jar)并同时进行控制台. 因此,默认情况下,控制台登录登录后的日志应转到System.out,然后使用kubectl logs可以看到该日志. 但这在我的应用程序中没有发生.
I read in kubernetes docs somewhere that kubernetes reads application logs from stdout and stderror in pods. I created a new application and configured it to send logs to a remote splunk hec endpoint (using splunk-logback jars) and at the same time to console. So by default, the console logs in logback should go to System.out, which should then be visible using kubectl logs . But it's not happening in my application.
我的登录文件:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<Appender name="SPLUNK" class="com.splunk.logging.HttpEventCollectorLogbackAppender">
<url>${splunk_hec_url}</url>
<token>${splunk_hec_token}</token>
<index>${splunk_app_token}</index>
<disableCertificateValidation>true</disableCertificateValidation>
<batch_size_bytes>1000000</batch_size_bytes>
<batch_size_count>${batch_size_count}</batch_size_count>
<send_mode>sequential</send_mode>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%msg</pattern>
</layout>
</Appender>
<Appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%msg</pattern>
</encoder>
</Appender>
<Appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="STDOUT" />
</Appender>
<root level="INFO">
<appender-ref ref="SPLUNK"/>
<appender-ref ref="ASYNC"/>
</root>
</configuration>
我能够看到splunk中的日志,如果我从后端登录到容器并启动我的Java应用程序,那么那时我也可以在终端上看到日志.但是,如果我让容器默认情况下自行启动,那么日志只会溢出,并且无法使用kubectl logs <POD_NAME>
I am able to see the logs in splunk and If I login to the container from backend and start my java application, then also I can see the logs on the terminal that time. But if I let the container start by default on it's own, then the logs are only going to splunk and I can't view them using kubectl logs <POD_NAME>
我的记录器应用程序的kubernetes yml文件:
The kubernetes yml file for my logger app:
apiVersion: v1
kind: Pod
metadata:
name: logging-pod
labels:
app: logging-pod
spec:
containers:
- name: logging-container
image: logger-splunk:latest
command: ["java", "-jar", "logger-splunk-1.0-SNAPSHOT.jar"]
resources:
requests:
cpu: 1
memory: 1Gi
limits:
cpu: 1
memory: 1Gi
推荐答案
确定,所以终于解决了.问题在于未刷新日志.
ok so this finally got resolved. The issue was with the logs not being flushed.
在PatternLayout中,%n丢失了.因此,我想一切都会进入缓冲,而无法到达控制台.
In the PatternLayout the %n was missing. Hence everything was going into some buffer I guess and not reaching the console.
这篇关于使用Java应用程序中的Logback配置发送到控制台的日志,使用Kubectl日志在Kubernetes中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!