apache - 如何在flume中设置日志文件名

标签 apache logging flume flume-ng flume-twitter

我正在使用 Apache Flume 进行日志收集。这是我的配置文件

httpagent.sources = http-source
httpagent.sinks = local-file-sink
httpagent.channels = ch3

#Define source properties 

httpagent.sources.http-source.type = org.apache.flume.source.http.HTTPSource
httpagent.sources.http-source.channels = ch3
httpagent.sources.http-source.port = 8082


# Local File Sink

httpagent.sinks.local-file-sink.type = file_roll
httpagent.sinks.local-file-sink.channel = ch3
httpagent.sinks.local-file-sink.sink.directory = /home/avinash/log_dir
httpagent.sinks.local-file-sink.sink.rollInterval = 21600

# Channels

httpagent.channels.ch3.type = memory
httpagent.channels.ch3.capacity = 1000

我的应用程序工作正常。我的问题是,在 log_dir 中,文件默认使用一些随机数(我猜是它的时间戳)时间戳。

如何为日志文件提供正确的文件名后缀?

最佳答案

看看documentation似乎没有参数用于配置要创建的文件的名称。我去了sources正在寻找一些隐藏参数,但没有人:)

深入了解实现的细节,似乎文件名是由PathManager管理的。类:

private PathManager pathController;
...
@Override
public Status process() throws EventDeliveryException {
    ...
    if (outputStream == null) {
        File currentFile = pathController.getCurrentFile();
        logger.debug("Opening output stream for file {}", currentFile);
        try {
            outputStream = new BufferedOutputStream(new FileOutputStream(currentFile));
    ...
}

正如您已经注意到的,它基于当前时间戳(显示构造函数和下一个文件 getter):

public PathManager() {
    seriesTimestamp = System.currentTimeMillis();
    fileIndex = new AtomicInteger();
}

public File nextFile() {
    currentFile = new File(baseDirectory, seriesTimestamp + "-" + fileIndex.incrementAndGet());
    return currentFile;
}

因此,我认为您唯一的可能性是扩展文件滚动接收器并重写 process() 方法,以便使用自定义路径 Controller 。

关于apache - 如何在flume中设置日志文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31135449/

相关文章:

flume - 配置 Flume 以监视目录中的新日志

apache - Shibboleth 忽略配置设置

regex - 解释这个mod_rewrite规则

apache - 如何将不同的子域请求重定向到不同的端口

android - 使用 Crashlytics 进行日志记录

c# - Serilog - 日志文件的路径

java - 将 html 设计集成到 servlet

java - 在 Android Studio logcat 中显示 java.util.logging.Logger 日志

hadoop - 以 hdfs 作为接收器的水槽中的 NoSuchMethod 错误

java - Flume的HttpSource : is the Jetty server multithread?