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
Related
ThreadLocal guard is utilized in doAppend method of Logback base appenders to prevent calling back on itself.
Under what circumstances would doAppend call back on itself?
Under what circumstances would doAppend call back on itself?
Anytime the Appender::append creates logging events that feedback into the appender itself. This is any Appender makes method calls against a 3rd party library which in itself uses a logging framework that uses slf4j or can be bridged to logback/slf4j.
Take the SMTPAppender as an example. Per the docs:
The SMTPAppender relies on the JavaMail API.
If the following statements are true then you have a feedback loop:
An ancestor of the JavaMail logger namespace has an attached SMTPAppender, say the root logger for example.
JavaMail session debugging has been enabled which will generate JUL log records on SMTP send.
The sl4fj JUL bridge handler is installed and is redirecting the JUL log records to the already attached SMTPAppender in point 1.
There is a running thread that tries to generate the first log message.
The SMTPAppender attempts to send email message. This action will generate more messages that feedback into logger in point 1.
When all of this is true, your application log message that you wanted to send via email ended up creating X number of log message debug statements from JavaMail. Those X number of message now end up calling SMTPAppender::append and so on.
This same type of example could be applied to the DBAppender which requires a JDBC driver that could be directly logging to slf4j. Same rules for any custom appenders applies here too.
In general, you don't what your application logs to be mixed with this appender generated log information or create some sort of feedback loop that takes down your server.
I looked up the api about the logger class(here) and I was looking at the Logger.info method. I was confused when I saw its perimeter as a message displayed as a string public void info(String msg) which is same as System.out.println(). I am wondering what is the different between these two, and why do we use Logger instead of System.out.println when they can print out the same thing.
In Logger.
Logger.info("Hello")
Output:
[INFO ] 2015-08-07 11:18:46.140 [main] ClassName Hello
In System.out.println
`System.out.println("Hello")
Output:
Hello
Usually, because a Logger can be configured to write to a file (and the console). It might also be configured at higher (or lower) granularity as to messaging. For example, you might configure (at runtime) for level of warn. In which case, that logger would not display debug or info messages. It can include information such as the class that is writing, a line number, and a date and time (of the message).
Using a logger allows you to abstract out a lot of details and do a lot more than you could writing to stdout.
You can specify different destinations to write to. Different appenders write to a file, roll the file for given time periods, write to a queue or database, etc.
You can specify a consistent format for log messages instead of having to add it to every line you write to stdout.
You can choose an appender that buffers the output so that multiple threads can log without having the threads contend for the lock on the console object.
You can do a lot with filtering by category (typically package and classname) and log level (trace, debug, info, error, fatal), to make it easy to configure what log messages you want to see and which you want to ignore. With logging you can change the configuration in the logger properties or include a page in your application to change what gets filtered on the fly.
You can mix and match this stuff, for instance, setting up a specific smtp appender to email log messages for logging level of error or higher, in addition to writing the messages to a rolling file or whatever.
The main difference between a Logger and System.out.println is Logger: Prints the text in a file(text file)System.out.println: Prints the output in console
Logger is useful when you are going for any LIVE projects. Because if any project is developed and deployed, then you cannot check the console. At that time Logger will be useful to track the flow of your project also you can find the Error or Exception if you have given the logger in catch{...} block.
Also go through this Logger vs. System.out.println
But when we use any logging mechanism(log4j, slf4j, logback etc) we
configure appenders and corresponding target log files for each
package. By default console appender is turned off unless you
explicitly configure it to log to a destination.
The System.out.println always logs the message to a console appender.
So, it should be used only when we are sure that the console appender
is configured in the logger configuration file. Otherwise we end up
having logs logged on server console which is incorrect. Any log from
inside the application should go to the corresponding application log
and not the server log.
Let me explain with an example.
If we are building an application called Tracker using a logging mechanism to run in a tomcat container, and we configured appenders for application logging with destination log file as tracker-application.log and we did not configure the console appender.
Then if the System.out.println is encountered by the JVM then the log will go to server log of the tomcat server which is wrong because server log should only have information about the server and not the application.
But if we created a console appender with a target log file then it will be logged properly.
Hope I was clear. ;)
For best practices refer Do not use System.out.println in server side code or http://www.vipan.com/htdocs/log4jhelp.html
For differences between both of them please refer
Logger vs. System.out.println
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
I'm struggling with this basic stuff for weeks already.
Can't make simple logs working in my Google App Engine (JAVA) app.
I started from this tutorial. Looks pretty straight forward.
Inside my Endpoint class I've defined a Logger like this:
private static final Logger log = Logger.getLogger(GowMainEndpoint.class.getName());
Then in one of my endpoint methods I tried to log event like:
log.info("test");
There is nothing showing up in logs. I have logging.properties file and appengine-web.xml configured just like in the mentioned tutorial.
EDIT: Weird thing: log.warning("test"); is showing up logs...
Ok I figured it out:
in the logging.properties file I've changed
.level = WARNING
to
.level = INFO
The comment line says:
# Set the default logging level for all loggers to INFO
but now I got the feeling it should be more like:
# Set the MINIMUM logging level for all loggers to INFO
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