如何将log4j2的日志输入到Java中的ByteBuffer中?

时间:2019-11-20 16:52:03

标签: maven log4j2 spring-boot-starter

我正在尝试将log4j2生成的本地日志上传到AWS S3存储桶,而不在本地存储日志。

我想将log4j2的日志直接传输到S3存储桶。

我认为该方法是将控制台日志放入ByteBuffer,然后通过AWS JAVA sdk v2上载到S3存储桶。

这是我的代码。

package com.ibiz.logging;

import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.Appender;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class S3LoggingApplication {

    // log instance create
    final static Logger logs = LogManager.getLogger(S3LoggingApplication.class);




    // why has to use string[] args?
    public static void main(String[] args) throws InterruptedException {


        // log gen
        logs.info("Log Gen Start!!!");
        logs.info("Log Gen Start!!!");
        logs.info("Log Gen Start!!!");
        logs.info("Log Gen Start!!!");
        Long started = System.currentTimeMillis();
        Long now = System.currentTimeMillis();

        // loop for 3 min
        // while (now - started < TimeUnit.MINUTES.toMillis(3)) {
        //     logs.info("You knock kncok mineral!");
        //     logs.warn("We are under attack!!");
        //     logs.error("Nuclear launch detected!!");
        //     logs.trace("GG");
        //     // term 7 sec
        //     Thread.sleep(TimeUnit.SECONDS.toMillis(7));
        // }
        // stream
        // InputStream input = new ByteArrayInputStream();        

        // input byte buffer        
        // ByteBuffer byteBuffer = ByteBuffer.wrap();

        // log gotcha


        // upload
        // S3Client s3 = S3Client.create();
        // TODO upload function

        // s3.putObject(PutObjectRequest.builder().bucket("jk.test").key("jk").build(), RequestBody.fromByteBuffer(byteBuffer));
}
}

0 个答案:

没有答案