How can I disable logging in Restlet 2.0?

前端 未结 6 749
梦如初夏
梦如初夏 2021-01-21 16:20

I simply want to disable Restlet\'s logging to stdout/stderr in my project and forward all Restlet logging through the SLF4J facade provided by org.restlet.ext.slf4j. Is there a

6条回答
  •  暖寄归人
    2021-01-21 16:52

    This is what I did to disable the logging to STDERR and forward the logging to log4j. Basicly it's just a base class from which all restlets are based. It will install the log4j bridge, find the console handler and disable it. Works for me but might not be the best solution so if anyone has a better solution which does not require external config, please let me know.

    public class CommonRestlet extends Application {
    
    static {
        // Install logging bridge (JUL -> LOG4J)
        SLF4JBridgeHandler.install();
    
        // Disable annoying console logging of requests..
        Logger logger = Logger.getLogger("org.restlet");
        for (Handler handler : logger.getParent().getHandlers()) {
            // Find the console handler
            if (handler.getClass().equals(java.util.logging.ConsoleHandler.class)) {
                // set level to SEVERE. We could disable it completely with 
                // a custom filter but this is good enough.
                handler.setLevel(Level.SEVERE);
            }
        }
    }
    // Other common stuff here...
    }
    

    Dependency in pom.xml

        
           org.slf4j
           jul-to-slf4j
           1.6.1
        
        
           org.slf4j
           slf4j-log4j12
           1.6.1
           
                
                    log4j
                    log4j
                
           
        
    

提交回复
热议问题