AWS streaming multi-line log files from CloudWatch to ELK











up vote
0
down vote

favorite












We are streaming app logs from CloudWatch to AWS ELK. Our microservices are written in Java and so I am only concentrating on those. A typical java exception stack trace when logged looks like this:



Exception in thread "main" java.lang.NullPointerException
at com.example.myproject.Book.getTitle(Book.java:16)
at com.example.myproject.Author.getBookTitles(Author.java:25)
at com.example.myproject.Bootstrap.main(Bootstrap.java:14)


Normally, this will be ingested line by line in ELK stack, which breaks the entire message.



Usually, For entire stack trace to be ingested as a single message, one can configure multiline plugin either in Logstash or Filebeat.



Any idea how to enable multiline while streaming log files from CloudWatch to ELK by AWS lambda?










share|improve this question






















  • What is your logging framework, and do you have any options to reconfigure it?
    – kdgregory
    Nov 10 at 12:13










  • And how are you writing the logs to CloudWatch? Are you running in Lambda and writing to its logger, or are you running in a container (or on EC2) and using the CloudWatch log agent? If the latter, then your problem is probably that agent, because it breaks the message into multiple lines in the log.
    – kdgregory
    Nov 10 at 12:14










  • @kdgregory slf4j with default config are used. any suggestions how to configure it? we run app in a container and use the CloudWatch log agent. is it possible to tell CloudWatch agent not break log per-line and combine them in case of sracktrace
    – Fedor
    Nov 10 at 12:31

















up vote
0
down vote

favorite












We are streaming app logs from CloudWatch to AWS ELK. Our microservices are written in Java and so I am only concentrating on those. A typical java exception stack trace when logged looks like this:



Exception in thread "main" java.lang.NullPointerException
at com.example.myproject.Book.getTitle(Book.java:16)
at com.example.myproject.Author.getBookTitles(Author.java:25)
at com.example.myproject.Bootstrap.main(Bootstrap.java:14)


Normally, this will be ingested line by line in ELK stack, which breaks the entire message.



Usually, For entire stack trace to be ingested as a single message, one can configure multiline plugin either in Logstash or Filebeat.



Any idea how to enable multiline while streaming log files from CloudWatch to ELK by AWS lambda?










share|improve this question






















  • What is your logging framework, and do you have any options to reconfigure it?
    – kdgregory
    Nov 10 at 12:13










  • And how are you writing the logs to CloudWatch? Are you running in Lambda and writing to its logger, or are you running in a container (or on EC2) and using the CloudWatch log agent? If the latter, then your problem is probably that agent, because it breaks the message into multiple lines in the log.
    – kdgregory
    Nov 10 at 12:14










  • @kdgregory slf4j with default config are used. any suggestions how to configure it? we run app in a container and use the CloudWatch log agent. is it possible to tell CloudWatch agent not break log per-line and combine them in case of sracktrace
    – Fedor
    Nov 10 at 12:31















up vote
0
down vote

favorite









up vote
0
down vote

favorite











We are streaming app logs from CloudWatch to AWS ELK. Our microservices are written in Java and so I am only concentrating on those. A typical java exception stack trace when logged looks like this:



Exception in thread "main" java.lang.NullPointerException
at com.example.myproject.Book.getTitle(Book.java:16)
at com.example.myproject.Author.getBookTitles(Author.java:25)
at com.example.myproject.Bootstrap.main(Bootstrap.java:14)


Normally, this will be ingested line by line in ELK stack, which breaks the entire message.



Usually, For entire stack trace to be ingested as a single message, one can configure multiline plugin either in Logstash or Filebeat.



Any idea how to enable multiline while streaming log files from CloudWatch to ELK by AWS lambda?










share|improve this question













We are streaming app logs from CloudWatch to AWS ELK. Our microservices are written in Java and so I am only concentrating on those. A typical java exception stack trace when logged looks like this:



Exception in thread "main" java.lang.NullPointerException
at com.example.myproject.Book.getTitle(Book.java:16)
at com.example.myproject.Author.getBookTitles(Author.java:25)
at com.example.myproject.Bootstrap.main(Bootstrap.java:14)


Normally, this will be ingested line by line in ELK stack, which breaks the entire message.



Usually, For entire stack trace to be ingested as a single message, one can configure multiline plugin either in Logstash or Filebeat.



Any idea how to enable multiline while streaming log files from CloudWatch to ELK by AWS lambda?







amazon-web-services elastic-stack amazon-cloudwatch amazon-elasticsearch






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 22:13









Fedor

609




609












  • What is your logging framework, and do you have any options to reconfigure it?
    – kdgregory
    Nov 10 at 12:13










  • And how are you writing the logs to CloudWatch? Are you running in Lambda and writing to its logger, or are you running in a container (or on EC2) and using the CloudWatch log agent? If the latter, then your problem is probably that agent, because it breaks the message into multiple lines in the log.
    – kdgregory
    Nov 10 at 12:14










  • @kdgregory slf4j with default config are used. any suggestions how to configure it? we run app in a container and use the CloudWatch log agent. is it possible to tell CloudWatch agent not break log per-line and combine them in case of sracktrace
    – Fedor
    Nov 10 at 12:31




















  • What is your logging framework, and do you have any options to reconfigure it?
    – kdgregory
    Nov 10 at 12:13










  • And how are you writing the logs to CloudWatch? Are you running in Lambda and writing to its logger, or are you running in a container (or on EC2) and using the CloudWatch log agent? If the latter, then your problem is probably that agent, because it breaks the message into multiple lines in the log.
    – kdgregory
    Nov 10 at 12:14










  • @kdgregory slf4j with default config are used. any suggestions how to configure it? we run app in a container and use the CloudWatch log agent. is it possible to tell CloudWatch agent not break log per-line and combine them in case of sracktrace
    – Fedor
    Nov 10 at 12:31


















What is your logging framework, and do you have any options to reconfigure it?
– kdgregory
Nov 10 at 12:13




What is your logging framework, and do you have any options to reconfigure it?
– kdgregory
Nov 10 at 12:13












And how are you writing the logs to CloudWatch? Are you running in Lambda and writing to its logger, or are you running in a container (or on EC2) and using the CloudWatch log agent? If the latter, then your problem is probably that agent, because it breaks the message into multiple lines in the log.
– kdgregory
Nov 10 at 12:14




And how are you writing the logs to CloudWatch? Are you running in Lambda and writing to its logger, or are you running in a container (or on EC2) and using the CloudWatch log agent? If the latter, then your problem is probably that agent, because it breaks the message into multiple lines in the log.
– kdgregory
Nov 10 at 12:14












@kdgregory slf4j with default config are used. any suggestions how to configure it? we run app in a container and use the CloudWatch log agent. is it possible to tell CloudWatch agent not break log per-line and combine them in case of sracktrace
– Fedor
Nov 10 at 12:31






@kdgregory slf4j with default config are used. any suggestions how to configure it? we run app in a container and use the CloudWatch log agent. is it possible to tell CloudWatch agent not break log per-line and combine them in case of sracktrace
– Fedor
Nov 10 at 12:31














1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










It turned out to be a know issue with AWS cloudwatch logger, see RichardBronosky's comment at https://github.com/visionmedia/debug/issues/296




I did some testing and found that CloudWatch log entries can be made multiline
by using r as the line delimiter. Using either n (Unix) or rn (DOS) line
endings will result in separate entries




So I fixed it by adding following ExceptionHandler to Spring Boot RestController



@ExceptionHandler(Throwable.class)
void handleUnhandledExceptions(Throwable e, HttpServletResponse response) throws IOException {
StringWriter buffer = new StringWriter();
e.printStackTrace(new PrintWriter(buffer));
log.error(buffer.toString().replace("n", "r"));
response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233934%2faws-streaming-multi-line-log-files-from-cloudwatch-to-elk%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    It turned out to be a know issue with AWS cloudwatch logger, see RichardBronosky's comment at https://github.com/visionmedia/debug/issues/296




    I did some testing and found that CloudWatch log entries can be made multiline
    by using r as the line delimiter. Using either n (Unix) or rn (DOS) line
    endings will result in separate entries




    So I fixed it by adding following ExceptionHandler to Spring Boot RestController



    @ExceptionHandler(Throwable.class)
    void handleUnhandledExceptions(Throwable e, HttpServletResponse response) throws IOException {
    StringWriter buffer = new StringWriter();
    e.printStackTrace(new PrintWriter(buffer));
    log.error(buffer.toString().replace("n", "r"));
    response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
    }





    share|improve this answer



























      up vote
      0
      down vote



      accepted










      It turned out to be a know issue with AWS cloudwatch logger, see RichardBronosky's comment at https://github.com/visionmedia/debug/issues/296




      I did some testing and found that CloudWatch log entries can be made multiline
      by using r as the line delimiter. Using either n (Unix) or rn (DOS) line
      endings will result in separate entries




      So I fixed it by adding following ExceptionHandler to Spring Boot RestController



      @ExceptionHandler(Throwable.class)
      void handleUnhandledExceptions(Throwable e, HttpServletResponse response) throws IOException {
      StringWriter buffer = new StringWriter();
      e.printStackTrace(new PrintWriter(buffer));
      log.error(buffer.toString().replace("n", "r"));
      response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
      }





      share|improve this answer

























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        It turned out to be a know issue with AWS cloudwatch logger, see RichardBronosky's comment at https://github.com/visionmedia/debug/issues/296




        I did some testing and found that CloudWatch log entries can be made multiline
        by using r as the line delimiter. Using either n (Unix) or rn (DOS) line
        endings will result in separate entries




        So I fixed it by adding following ExceptionHandler to Spring Boot RestController



        @ExceptionHandler(Throwable.class)
        void handleUnhandledExceptions(Throwable e, HttpServletResponse response) throws IOException {
        StringWriter buffer = new StringWriter();
        e.printStackTrace(new PrintWriter(buffer));
        log.error(buffer.toString().replace("n", "r"));
        response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
        }





        share|improve this answer














        It turned out to be a know issue with AWS cloudwatch logger, see RichardBronosky's comment at https://github.com/visionmedia/debug/issues/296




        I did some testing and found that CloudWatch log entries can be made multiline
        by using r as the line delimiter. Using either n (Unix) or rn (DOS) line
        endings will result in separate entries




        So I fixed it by adding following ExceptionHandler to Spring Boot RestController



        @ExceptionHandler(Throwable.class)
        void handleUnhandledExceptions(Throwable e, HttpServletResponse response) throws IOException {
        StringWriter buffer = new StringWriter();
        e.printStackTrace(new PrintWriter(buffer));
        log.error(buffer.toString().replace("n", "r"));
        response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 10 at 22:55

























        answered Nov 10 at 21:40









        Fedor

        609




        609






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233934%2faws-streaming-multi-line-log-files-from-cloudwatch-to-elk%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            The Sandy Post

            Danny Elfman

            Pages that link to "Head v. Amoskeag Manufacturing Co."