0

I am using Tomcat (7.0.70) + sentry (both sentry and sentry-spring) + JUL with the following logging.properties file in WEB-INF/classes:

handlers = java.util.logging.FileHandler,java.util.logging.ConsoleHandler,io.sentry.jul.SentryHandler

# Default global logging level.
# Loggers and Handlers may override this level
.level = INFO

#Format
java.util.logging.SimpleFormatter.format = %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$-8s --- %2$-100s : %5$s%6$s%n

# Handlers
# -----------------------------------------

# --- ConsoleHandler ---
# Override of global logging level
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

# --- FileHandler ---
java.util.logging.FileHandler.level = FINE
java.util.logging.FileHandler.pattern = ${catalina.base}/logs/application.%g.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter

io.sentry.jul.SentryHandler.level = SEVERE

My issue is that all logs are sent to sentry, instead of only the SEVERE ones. I also noticed that if I changed the global .level it had an impact on which logs were sent to sentry (ie if I set it to WARNING, only warnings are logged and sent to sentry).

Do you have any idea what I am doing wrong?

Thanks!

Sébastien Tromp
  • 603
  • 1
  • 15
  • 30

1 Answers1

0

Do you have any idea what I am doing wrong?

If I'm looking at the right source code, it is not attempting to read the settings from the LogManager. You can extend SentryHandler and have the sub class read from the LogManager and set the level. Or you need to create code to find the SentryHandler and set the level.

If possible, try setting some of the configuration in $CATALINA_BASE/conf instead of the WEB-INF/classes.

If you look at the source code, the logger levels are only set once in addLogger method. The WEB-INF/classes is going to be loaded in readConfiguration(ClassLoader). If any class loading triggers the logger creation it could occur before readConfiguration(ClassLoader). In that case, the logger level is never changed by the WEB-INF/classes logging.properties.

You should be able to declare some of the logger levels in $CATALINA_BASE/conf and the handler installation in WEB-INF/classes.

Try printing the logger tree from the application classloader. This can be as simple as just including a servlet with the application to print the logger tree. Maybe something is resetting your configuration or the level is not being set on the handler.

jmehrens
  • 10,580
  • 1
  • 38
  • 47
  • Interesting. I did some tests and added the `io.sentry.jul.SentryHandler.level = SEVERE` declaration to `logging.properties` in `$CATALINA_BASE/conf` but to no avail (no change). Defining the handler there is a bit tricky, since Tomcat doesn't have `sentry` jars in its classpath. I'll try adding them, though I'll be pulling a lot of dependencies – Sébastien Tromp Sep 19 '17 at 19:59
  • Adding all the dependencies causes the startup error `java.lang.ClassNotFoundException: javax.servlet.ServletContainerInitializer`, probably because of a conflict with some embedded libs? – Sébastien Tromp Sep 19 '17 at 20:01
  • I tried most of the different combinations - declaring everything but the handler in the `base` and the rest in `web-inf`, but to no avail. – Sébastien Tromp Sep 20 '17 at 06:26
  • Looks like a bug in the handler implementation. See the answer edits. – jmehrens Sep 22 '17 at 21:44