Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see org.codehaus.jackson log messages - using logging.properties

I am trying to deserialize incoming PUT request with JSON request body using org.codehaus.jackson package and I am receiving error message The request sent by the client was syntactically incorrect. How can I get more detailed log/error messages in my Pivotal TC server logs, e.g. in catalina.log?

I have added the following line to logging.properties:

org.codehaus.level = FINEST

But NO messages from org.codehaus is displayed in my log, although the error message is displayed on web page. Maybe codehaus does not support Java logging and I should configure J4Log or similar another logging facility?

My Jackson version is 1.9.13, I am using Pivotal tc server from Spring Tools Suite (3.8).

like image 771
TomR Avatar asked Aug 14 '17 12:08

TomR


People also ask

How do you log messages in Java?

There are the five logging handlers in Java: StreamHandler: It writes the formatted log message to an OutputStream. ConsoleHandler: It writes all the formatted log messages to the console. FileHandler: It writes the log message either to a single file or a group of rotating log files in the XML format.

What is org Codehaus Jackson?

org.codehaus.jackson » jackson-lgplLGPL. Jackson is a high-performance JSON processor (parser, generator)

Does Java Util logging use Log4j?

The JDK Logging Adapter is a custom implementation of java. util. logging. LogManager that uses Log4j.

What is the use of logger info in Java?

A Logger object is used to log messages for a specific system or application component. Loggers are normally named, using a hierarchical dot-separated namespace. Logger names can be arbitrary strings, but they should normally be based on the package name or class name of the logged component, such as java.net or javax.

What are the best libraries for logging in Java?

Both use Jackson internally for representing logs in the JSON format. For an introduction to these libraries take a look at our introduction to Java Logging article. 2. Log4j2 Log4j2 is the direct successor of the most popular logging library for Java, Log4J. As it's the new standard for Java projects, we'll show how to configure it to output JSON.

Where can I find the previous versions of the Log4j dependencies?

The latest versions of the previous dependencies can be found on Maven Central: log4j-api, log4j-core, jackson-databind. 2.2. Configuration

How to add your own values to the log?

As we can see in the example config, it's possible to add our own values to the log using KeyValuePair, that even supports lookout into the log context. Setting the compact parameter to false will increase the size of the output but will make it also more human readable. 2.3. Using Log4j2

How do I get a JSON file from a Logback?

First, we create a new appender in our logback.xml that uses JsonLayout and JacksonJsonFormatter. After that, we can create a new logger that uses this appender: As we see, the parameter prettyPrint is enabled to obtain a human-readable JSON.


2 Answers

For what you say it seems that you're trying to change the tomcat logging.properties.

That's usually a bad idea as you may want different logging on different webApps loaded in the same Tomcat server.

What you should do is configure the log4j in your project. Usually Java projects define a "resource" folder. You should add in there a file called

log4j.properties

and add in there the following:

log4j.rootLogger=ERROR,stdout
# Logger for jackson lib
log4j.logger.org.codehaus=TRACE

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p\t%d{ISO8601}\t%r\t%c\t[%t]\t%m%n

This is extracted from the default log4j configuration and will log in the standard output that for Tomcat is redirected to the catalina.out log file. You may want to read the documentation at https://docs.oracle.com/cd/E29578_01/webhelp/cas_webcrawler/src/cwcg_config_log4j_file.html explaining how to redirect the logging to a different file and how to use rolling appenders so you keep some history

Hopefully this will work!

like image 182
gmcontessa Avatar answered Oct 20 '22 21:10

gmcontessa


The request sent by the client was syntactically incorrect

^^^ This message is created by the HTTP servlet processing the client request and not by the jackson mapper. You could find the related log messages under spring-mvc logger name: org.springframework.web.

like image 31
Steve Oh Avatar answered Oct 20 '22 23:10

Steve Oh