Git Product home page Git Product logo

Comments (5)

ppkarwasz avatar ppkarwasz commented on June 14, 2024

You are calling BufferedReader#readLine() twice per loop iteration.

Try:

JsonLogEventParser parser = new JsonLogEventParser();
try (BufferedReader br = new BufferedReader(new FileReader(logFilePath))) {
        String line;
	while ((line = br.readLine()) != null) {
	        // Get LOG Event from line
	        try {
			LogEvent logEvent = parser.parseFrom(line);
                        .....
                }
                catch(Exception x) {
			System.out.print("Error parsing log");
			throw x;
		}
       }
}   
catch(Exception e) {
	System.out.println(e.getStackTrace().toString());
	throw new RuntimeException(e);
}

You are also assuming that each log line has one JSON object, which might be wrong.

BTW: we are considering removing the whole o.a.l.l.core.parser package from log4j-core (cf. this thread on dev@logging).

from logging-log4j2.

sanova avatar sanova commented on June 14, 2024

Thank you for your answer. Yes you are right regarding reading buffered line twice. But error persists. It's related only to the stacktrace part of json. it works fine if stacktrace is not present.
Anyway, if the parser package will be removed from core, i have to implement my own parser json log.
Thank you for you support.

from logging-log4j2.

sanova avatar sanova commented on June 14, 2024

If the parser package will be removed from core i can close the issue

from logging-log4j2.

vy avatar vy commented on June 14, 2024

@sanova, I recommend you to indeed roll out your own parser.

Back in the days when JsonLayout was the only JSON-formatted layout, it was possible to provide Jackson-annotated DTOs to parse LogEvents. With the introduction of JsonTemplateLayout, the user is given full control over the JSON structure, hence it is not possible to provide a parser, since the structure is not known to Log4j.

@sanova, if I may ask, what is your use case? Why do you need to parse logs back into Log4j LogEvents? What do you do with it?

from logging-log4j2.

ppkarwasz avatar ppkarwasz commented on June 14, 2024

For completeness' sake, the parser didn't disappear, it was moved to samples: log4j-samples-parser.

from logging-log4j2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.