/** * 开启DEBUG级别日志(仅针对JDK14LOGGER,LOG4J请自行修改配置文件) * * @param isEnabled */ public static void setJDKDebugEnabled(Boolean isEnabled) { //如果使用JDK14LOGGER,将业务日志级别设为DEBUG(FINE) if (blog instanceof Jdk14Logger) { Jdk14Logger logger = (Jdk14Logger) blog; if (isEnabled) { logger.getLogger().setLevel(Level.FINE); Handler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.FINE); logger.getLogger().addHandler(consoleHandler); } else { logger.getLogger().setLevel(Level.INFO); } } }
public static void setJDKDebugEnabled(Boolean isEnabled) { //如果使用JDK14LOGGER,将业务日志级别设为DEBUG(FINE) if (blog instanceof Jdk14Logger) { Jdk14Logger logger = (Jdk14Logger) blog; if (isEnabled) { logger.getLogger().setLevel(Level.FINE); Handler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.FINE); logger.getLogger().addHandler(consoleHandler); } else { logger.getLogger().setLevel(Level.INFO); } } }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { // Do the authorization if (!HttpServer.hasAdministratorAccess(getServletContext(), request, response)) { return; } PrintWriter out = ServletUtil.initHTML(response, "Log Level"); String logName = ServletUtil.getParameter(request, "log"); String level = ServletUtil.getParameter(request, "level"); if (logName != null) { out.println("<br /><hr /><h3>Results</h3>"); out.println(MARKER + "Submitted Log Name: <b>" + logName + "</b><br />"); Log log = LogFactory.getLog(logName); out.println(MARKER + "Log Class: <b>" + log.getClass().getName() +"</b><br />"); if (level != null) { out.println(MARKER + "Submitted Level: <b>" + level + "</b><br />"); } if (log instanceof Log4JLogger) { process(((Log4JLogger)log).getLogger(), level, out); } else if (log instanceof Jdk14Logger) { process(((Jdk14Logger)log).getLogger(), level, out); } else { out.println("Sorry, " + log.getClass() + " not supported.<br />"); } } out.println(FORMS); out.println(ServletUtil.HTML_TAIL); }
/** * Switches the logger for the given class to DEBUG level. * * @param clazz The class for which to switch to debug logging. */ public void enableDebug(Class<?> clazz) { Log l = LogFactory.getLog(clazz); if (l instanceof Log4JLogger) { ((Log4JLogger) l).getLogger().setLevel(org.apache.log4j.Level.DEBUG); } else if (l instanceof Jdk14Logger) { ((Jdk14Logger) l).getLogger().setLevel(java.util.logging.Level.ALL); } }
/** * Switches the logger for the given class to DEBUG level. * * @param clazz The class for which to switch to debug logging. */ public void enableDebug(Class<?> clazz) { Logger l = LoggerFactory.getLogger(clazz); if (l instanceof Log4JLogger) { ((Log4JLogger) l).getLogger().setLevel(org.apache.log4j.Level.DEBUG); } else if (l instanceof Log4jLoggerAdapter) { LogManager.getLogger(clazz).setLevel(org.apache.log4j.Level.DEBUG); } else if (l instanceof Jdk14Logger) { ((Jdk14Logger) l).getLogger().setLevel(java.util.logging.Level.ALL); } }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { // Do the authorization if (!HttpServer.hasAdministratorAccess(getServletContext(), request, response)) { return; } PrintWriter out = ServletUtil.initHTML(response, "Log Level"); String logName = ServletUtil.getParameter(request, "log"); String level = ServletUtil.getParameter(request, "level"); if (logName != null) { out.println("<br /><hr /><h3>Results</h3>"); out.println(MARKER + "Submitted Log Name: <b>" + logName + "</b><br />"); Logger log = LoggerFactory.getLogger(logName); out.println(MARKER + "Log Class: <b>" + log.getClass().getName() +"</b><br />"); if (level != null) { out.println(MARKER + "Submitted Level: <b>" + level + "</b><br />"); } if (log instanceof Log4JLogger) { process(((Log4JLogger)log).getLogger(), level, out); } else if (log instanceof Jdk14Logger) { process(((Jdk14Logger)log).getLogger(), level, out); } else if (log instanceof Log4jLoggerAdapter) { process(LogManager.getLogger(logName), level, out); } else { out.println("Sorry, " + log.getClass() + " not supported.<br />"); } } out.println(FORMS); out.println(ServletUtil.HTML_TAIL); }
@Override public void init(ServletConfig config) throws ServletException { super.init(config); moduleManager=new ModuleManager(); servletHome=config.getServletContext().getRealPath("/")+"WEB-INF"; moduleManager.setVariable("servletHome", servletHome); // SimpleLog log=new SimpleLog("ModulesServlet"); // log.setLevel(SimpleLog.LOG_LEVEL_DEBUG); Log log=new Jdk14Logger("ModulesServlet"); moduleManager.setLogging(log); String configFile=config.getInitParameter("modulesconfig"); if(configFile==null) { configFile=config.getInitParameter("modulesConfig"); if(configFile==null) configFile="modulesconfig.xml"; } bindAddress=config.getInitParameter("bindaddress"); if(bindAddress==null){ bindAddress=config.getInitParameter("bindAddress"); } moduleManager.addModule(servletModule,new ModuleSettings("rootServlet")); moduleManager.readXMLOptionsFile(configFile); if(bindAddress==null){ bindAddress=moduleManager.getVariable("bindAddress"); if(bindAddress==null) bindAddress=DEFAULT_BIND_ADDRESS; } try{ moduleManager.autostartModules(); }catch(ModuleException me){ throw new ServletException("Unable to start modules.",me); } }
public WandoraModulesServer(Wandora wandora){ this.wandora = wandora; jettyServer = new Server(); rootLog = new Jdk14Logger("ModulesServlet"); log = rootLog; Options options = wandora.getOptions(); readOptions(options); mimeTypes = new MimeTypes(); initModuleManager(); readBundleDirectories(); }
@Test public void run() throws OpenEJBException, NamingException, IOException { final File tempWar = new File("target/AppDataSourceTest"); tempWar.mkdirs(); new File(tempWar, "WEB-INF").mkdirs(); IO.writeString(new File(tempWar, "WEB-INF/resources.xml"), "<resources>\n" + "<Resource id=\"java:app/gace/MyDS\" type=\"DataSource\">\n" + "DataSourceCreator=dbcp\n" + "</Resource>\n" + "</resources>\n"); final Collection<LogRecord> records = new ArrayList<>(); try (final Container c = new Container(new Configuration().randomHttpPort())) { Jdk14Logger.class.cast(LogFactory.getLog(BasicDataSource.class)).getLogger().addHandler(new Handler() { @Override public void publish(final LogRecord record) { if (record.getLevel() == Level.SEVERE || record.getLevel() == Level.WARNING) { records.add(record); } } @Override public void flush() { // no-op } @Override public void close() throws SecurityException { // no-op } }); c.deploy(null, tempWar); } // if we have the JMX bug of dbcp2 integration (in 7.0.0) then we have a WARNING record from BasicDataSource.close() // saying: // Failed to unregister the JMX name: // Tomcat:type=DataSource,host=localhost,context=/AppDataSourceTest,class=javax.sql.DataSource,name="openejb/Resource/AppDataSourceTest/app/gace/MyDS" assertTrue(records.isEmpty()); }
@Before public void init() throws SecurityException, IOException { this.defaultLocale = Locale.getDefault(); Locale.setDefault(Locale.ENGLISH); this.logger = new Jdk14Logger(getClass().getName()); }