/** * Assimilate a small set of logging frameworks. */ public static synchronized void assimilate() { if (assimilated) { return; } assimilated = true; // Assimilate java.util.logging final Logger rootLogger = LogManager.getLogManager().getLogger(""); final Handler[] handlers = rootLogger.getHandlers(); if (handlers != null) { for (Handler handler : handlers) { rootLogger.removeHandler(handler); } } SLF4JBridgeHandler.install(); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); lc.addListener(new LevelChangePropagator()); try { lc.addListener(new JMXConfigurator(lc, ManagementFactory.getPlatformMBeanServer(), new ObjectName("com.opentable.logging:name=LogbackConfig"))); } catch (MalformedObjectNameException e) { throw new RuntimeException(e); } LoggerFactory.getLogger(AssimilateForeignLogging.class).info("java.util.logging was assimilated."); }
public void configure() { //detach current appenders; getCleanRoot(); hijackJDKLogging(); final Logger root = configureLevels(); for (Appender<ILoggingEvent> appender : LogbackFactory.buildAppenders( config.getServerLogConfiguration(), root.getLoggerContext())) { root.addAppender(AsyncAppender.wrap(appender)); } final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); try { final ObjectName objectName = new ObjectName("grails.plugin.lightweightdeploy:type=Logging"); if (!server.isRegistered(objectName)) { server.registerMBean(new JMXConfigurator(root.getLoggerContext(), server, objectName), objectName); } } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { addInfo("begin"); String contextName = context.getName(); String contextNameAttributeVal = attributes .getValue(CONTEXT_NAME_ATTRIBUTE_NAME); if(!OptionHelper.isEmpty(contextNameAttributeVal)) { contextName = contextNameAttributeVal; } String objectNameAsStr; String objectNameAttributeVal = attributes .getValue(OBJECT_NAME_ATTRIBUTE_NAME); if (OptionHelper.isEmpty(objectNameAttributeVal)) { objectNameAsStr = MBeanUtil.getObjectNameFor(contextName, JMXConfigurator.class); } else { objectNameAsStr = objectNameAttributeVal; } ObjectName objectName = MBeanUtil.string2ObjectName(context, this, objectNameAsStr); if (objectName == null) { addError("Failed construct ObjectName for ["+objectNameAsStr+"]"); return; } MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); if(!MBeanUtil.isRegistered(mbs, objectName)) { // register only of the named JMXConfigurator has not been previously // registered. Unregistering an MBean within invocation of itself // caused jconsole to throw an NPE. (This occurs when the reload* method // unregisters the JMXConfigurator jmxConfigurator = new JMXConfigurator((LoggerContext) context, mbs, objectName); try { mbs.registerMBean(jmxConfigurator, objectName); } catch (Exception e) { addError("Failed to create mbean", e); } } }
public void configure() { hijackJDKLogging(); final Logger root = configureLevels(); final LoggingConfiguration.ConsoleConfiguration console = config.getConsoleConfiguration(); if (console.isEnabled()) { root.addAppender(AsyncAppender.wrap( LogbackFactory.buildConsoleAppender( console, root.getLoggerContext(), console.getLogFormat()))); } final LoggingConfiguration.FileConfiguration file = config.getFileConfiguration(); if (file.isEnabled()) { root.addAppender(AsyncAppender.wrap( LogbackFactory.buildFileAppender( file, root.getLoggerContext(), file.getLogFormat()))); } final LoggingConfiguration.SyslogConfiguration syslog = config.getSyslogConfiguration(); if (syslog.isEnabled()) { root.addAppender(AsyncAppender.wrap( LogbackFactory.buildSyslogAppender( syslog, root.getLoggerContext(), name, syslog.getLogFormat()))); } final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); try { final ObjectName objectName = new ObjectName("com.ir:type=Logging"); if (!server.isRegistered(objectName)) { server.registerMBean(new JMXConfigurator(root.getLoggerContext(), server, objectName), objectName); } } catch (Exception e) { throw new RuntimeException(e); } }