SLF4J logs error messages at info level - java

I'm running into a weird problem. I have a class that used to use Log4j, and I could do something like:
LOGGER.log(Level.SEVERE, "This is a message");
And I'd get output like this:
SEVERE: This is a message
I replaced it with an SLF4J logger for consistency with the rest of the application:
LOGGER.error("This is a message.");
But now it's logging at INFO level:
INFO: 2012-01-23 16:50:43,306 [http-thread-pool-8080(3)] ERROR com.mycompany.MyClass - This is a message
I was expecting this to be logged at ERROR level (SLF4J doesn't seem to have any levels above that).
Any idea what's going on? Is this the default? The application is fairly complicated, so I wouldn't be surprised if this was changed somewhere, but where would I find that to change it back?
I'm using Glassfish, in case that might be related.

you need to make your SLF4J use the Java Util Logging backend. That's what Glassfish uses internally. Since it's not using that, it's dumping to the console, and GF reports everything on the console as INFO.
So hook up the JUL adapter and you should be all good.

without configuration listing for logging it's only a guess. but I think the logging framework is probably misconfigured. slf4j logs at ERROR level:
ERROR com.mycompany.MyClass - This is a message
then this output is sent into console, which is redirected into general log file at INFO level by glassfish.
previous setup probably used glassfish logging directly inheriting its configuration. after switching to slf4j no config was found so everything is sent to console and then to server.log

Related

How to suppress local info logs from Sentry in Java?

I'm using Sentry to log errors that occur in my code and every time I launch my application I see that Sentry logs information like
[main] INFO io.sentry.DefaultSentryClientFactory - Using an HTTPS connection to Sentry.
Is it possible to suppress this kind of logs?
I don't know which logging framework you are using but each of them offers a way to change the threshold for a specific package (or class), so you could just disable or raise it for io.sentry.DefaultSentryClientFactory. For example, here's one for log4j: https://stackoverflow.com/a/4973082/11958
PS: I work on sentry-java and I think those shouldn't be at the INFO level, honestly. I'll change that in a future release.

How to configure ruby puts logs to show up in Java-JRuby log file

I have configured JRuby within my JAX-RS application to run some ruby scripts. For debugging, I have used some "puts" statements in the ruby file. They are not getting logged in the JAX-RS webservice log file. How to configure?
Basically I want ruby "puts" logs to display in dropwizard webservice log
This page describes how to override puts in ruby with new behavior
Ruby: overriding the puts method
You can then use org.slf4j.LoggerFactory.getLogger , org.apache.commons.logging.LogFactory.getLog (etc) from inside the overridden function.
I think I figured it out.
Since jruby-complete dependency is brining in apache-commons-logging jar, I used the following statements in the ruby script and it logged it to the configured webservice log
age = 10
log = org.apache.commons.logging.LogFactory.getLog(self.class.name)
log.info("hello from ruby " + age.to_s)
I just noticed that I was able to use slf4j too
log = org.slf4j.LoggerFactory.getLogger(self.class.name)
The logging level depends on what we set at the root level in config.yaml. Only if that is set to DEBUG, we can see log.debug entries.
logging:
# The default level of all loggers. Can be OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
level: DEBUG
I also noticed configuring log level at the package/class level, does not log “debug” statements from ruby
loggers:
# Sets the level for 'com.example.app' to DEBUG.
com.example.test: DEBUG

Logging issue with Spring (core & jdbc not MVC)

My application is using Spring to handle the interaction with database (Sql Server)
And commons-logging-1.1.1.jar, log4j-1.2.17.jar, slf4j-api-1.6.3.jar and slf4j-log4j12-1.7.6.jar are put into build path for the logging framework of the application.
The last two logging jar (slf4j-api and slf4j-log4j12) are for another component inside the application to use log4j.
Here is my questions:
When Spring-Jdbc runtime excecption happens, the exception is only showed in the console of eclipse with the font color red. The exception is NOT logged into the log file. But the normal log (like log.info(...)) are all in the log file. Why can't the run-time exception be in the log file and how to solve this problem.
When I use SimpleJdbcCall to call the stored procedure with parameters in MapSqlParameterSource, the following log shows up:
14:43:30 [INFO ] Added default SqlReturnUpdateCount parameter named #update-count-1
14:43:30 [INFO ] Added default SqlReturnUpdateCount parameter named #update-count-1
......
It's really annoying because the number of this message is so large. I want to turn off this particular log message without affecting another logging with the same level (INFO)
And my log4j.xml is fine I think because the logging are basically fine except the above issues.
Spring is using commons-logging internally that's why you can see the messages in your eclipse console. To redirect commons-logging to slf4j/log4j you need to remove commons-logging-1.1.1.jar from your classpath and add jcl-over-slf4j.jar from your slf4j version. To get rid of the dublicate red eclipse messages (jul and jcl) you can set the logging level in logging.properties for the console handler to warning:
java.util.logging.ConsoleHandler.level = WARNING
Second issue was solved here.

Websphere with Logback logging to system out - formatting issue

I am using Logback in my application hosted on Websphere App Server. Logback is configured to log to System Out (and others are hesitant to change to a different file). The issue is that Websphere uses its own format for logging to System Out. Executing logger.debug("test") in my app yields:
[8/7/12 12:27:55:629 CDT] 0000003a SystemOut O DEBUG com.myapp... test
where everything up to the "O" is added by Websphere. The rest is from Logback
I have set up Logback to use the following pattern: %-5level %logger{36} - %msg%n so that I don't repeat timestamp and thread info which Websphere does on its own, but I am still annoyed that I can't fully customize the logging to System Out from within Logback.
I don't know a whole lot about logging best practices. Before, I have logged to separate files by web app, but for this project, I was told the System Out files are monitored by a third party and I should not change from using System Out. Is there any way to get around my issue given these requirements and tell Websphere not to mess with my System Out logging, or is the only solution to start logging to a different file? Thanks!
Your logback is configured to write messages to System.out. However, everything that is written to System.out is redirected by WebSphere and written to the SystemOut.log file with the same format as log messages produced by WebSphere, but with a severity indicator "O". It is not possible to change that.
Note that it is likely that the people who told you to use SystemOut.log actually meant that you should ensure that logging is done using WebSphere's log system so that messages are written with the correct category and severity and that log levels can be changed at runtime. Since WebSphere's log system is build on java.util.logging you should probably just replace logback by slf4j-jdk14 to satisfy their requirement.
I don't think you're going to be able to change the format. And if you could, it might break the current monitoring anyway.
I wonder if anyone would mind if you log to two loggers at the same time, SystemOut for the existing monitoring, and your own for a more readable format.
The problem is that Logback redirects the messages to console output instead of java.util.logging. Console output has no log levels and that's why WebSphere just writes "O".
We solved this by implementing a Logback appender that redirects logs to JUL (java.util.logging) instead. We convert Logback log levels to JUL levels (e.g. Logback "ERROR" is JUL "SEVERE").
We also wanted to use Websphere's trace options. If trace is enabled for a class/package pattern, you will see Logback DEBUG and TRACE messages in Websphere's trace.log. You can also check if the trace is enabled by calling Logback's isDebugEnabled() / isTraceEnabled().
See this answer with a full implementation:
https://stackoverflow.com/a/74386323/395879

Google App Engine - Can not find my logging messages

I can not find the results of my logging calls.
To log messages I tried both:
System.out.println("some message");
and
Logger logger = Logger.getLogger("MyLogger"); // Logger is java.util.logging.Logger
// ...
logger.info("some message");
I have deployed my app and after few tests I decided check out some
log messages. But there were no messages. I changed minimum severity
level to "Info" from default "Error", and only messages i've seen were
service messages like this:
http://dl.dropbox.com/u/1678938/logs.png
I would also be grateful if someone show a little snippet with logging some data (if it's works) - I suspect my problem may be the one of that stupid problems when somewhat incorrectly located comma can be the cause of situation.
Could it be that your logging.properties is setting the default value to WARNING?
Ours has this in our war/WEB-INF/logging.properties file:
# Set the default logging level for all loggers to WARNING
.level = WARNING
# Default level for subpackages of 'server' will be INFO
com.company.whatever.server.level=INFO
Problem has shrunk into more concrete form - App Engine "eats" info-messages, but shows others, such as error and warning messages.
After this call I have eventually seen my info messages:
log.setLevel(Level.INFO);
But it is still not clearly - why info-messages weren't being shown. Google's manual states:
Everything the servlet writes to the
standard output stream (System.out)
and standard error stream (System.err)
is captured by App Engine and recorded
in the application logs. Lines written
to the standard output stream are
logged at the "INFO" level, and lines
written to the standard error stream
are logged at the "WARNING" level.
Had exactly the same problem and after changing the value in logging.properties from
.level = WARNING
to
.level = INFO
The problem was definitively fixed. Google needs to update their documentation and/or change the value of the supplied default so that "INFO" log messages don't get swallowed.
I used to set LEVEL to SEVERE for testing
logger.log(Level.SEVERE, "test message");
It does not need changing any value in logging.properties

Categories

Resources