Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom log handler to Google App Engine?

I am trying to add a custom log handler to my java application. I have implemented a InnerLogger class that extends java.util.Logging.Handler class. And in my logging.properties declared as a handler:

handlers:com.mycompany.util.InnerLogger

But when I launch the development sever, I got the following error:

Can't load log handler "com.mycompany.util.InnerLogger"
java.lang.ClassNotFoundException: com.mycompany.util.InnerLogger

I can add my custom handler to loggers one by one ,but I just wondering is there a way to add it to all loggers.

Thanks

like image 408
aimless Avatar asked Mar 23 '12 14:03

aimless


2 Answers

I was able to add a Handler to the root Logger when my application initializes. You can put this code in a warmup task or servlet filter.

private static Logger LOG;

...

LOG = Logger.getLogger("");
LOG.addHandler(myCustomHandler);

Its not as graceful as using logging.properties, but it is an adequate workaround when running on GAE.

like image 67
Brad Avatar answered Oct 02 '22 15:10

Brad


It might not the solution you were looking for, but have you considered using Simple Logging Facade for Java (SLF4J) in your application instead of using directly JUL?

like image 34
Le Hibou Avatar answered Oct 02 '22 13:10

Le Hibou