Comments (5)
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.
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.
If the parser package will be removed from core i can close the issue
from logging-log4j2.
@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 LogEvent
s. 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 LogEvent
s? What do you do with it?
from logging-log4j2.
For completeness' sake, the parser didn't disappear, it was moved to samples: log4j-samples-parser
.
from logging-log4j2.
Related Issues (20)
- Revamp the `Configuration` page HOT 2
- Revamp the `Lookups` page
- Revamp the `Layouts` page
- Revamp the `Appenders` page HOT 1
- Revamp the `Filters` page
- Revamp the `Extending` page
- Revamp the `Plugins` page
- Create a `Troubleshooting` page HOT 1
- Revamp the `Performance` page
- Revamp the `Asynchronous logging` page
- Revamp the `API` page
- Uniform handling of location and URIs HOT 1
- [MS14] Documentation revamp 1/5 HOT 1
- [MS15] Documentation revamp 2/5
- [MS16] Documentation revamp 3/5
- [MS17] Documentation revamp 4/5
- [MS18] Documentation revamp 5/5
- Revamp the `Web Applications` page
- Implement uniform password "encryption/decryption" mechanism HOT 4
- When logging from multiple threads, an appender can be broken until app restart if it rolls over HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logging-log4j2.