public static ShellLogHandler getLogHandler(Map<String, Object> topoConf) { if (topoConf == null) { throw new IllegalArgumentException("Config is required"); } String logHandlerClassName = null; if (topoConf.containsKey(Config.TOPOLOGY_MULTILANG_LOG_HANDLER)) { try { logHandlerClassName = topoConf.get(Config.TOPOLOGY_MULTILANG_LOG_HANDLER).toString(); return (ShellLogHandler) Class.forName(logHandlerClassName).newInstance(); } catch (ClassCastException | InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new RuntimeException("Error loading ShellLogHandler " + logHandlerClassName, e); } } return new DefaultShellLogHandler(); }
/** * This default implementation saves the {@link ShellProcess} so it can output the process info string later. * * @param ownerCls - the class which instantiated this ShellLogHandler. * @param process - the current {@link ShellProcess}. * @param context - the current {@link TopologyContext}. * @see {@link ShellLogHandler#setUpContext} */ public void setUpContext(final Class<?> ownerCls, final ShellProcess process, final TopologyContext context) { this.log = getLogger(ownerCls); this.process = process; // context is not used by the default implementation, but is included // in the interface in case it is useful to subclasses }
/** * A null {@link ShellMsg} will throw IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void handleLog_nullShellMsg() { logHandler.log(null); }
/** * It's fine to pass only null arguments to setUpContext. */ @Test public void setUpContext_allNull() { ShellMsg msg = mockMsg(); logHandler.setUpContext(null, null, null); logHandler.log(msg); verify(msg).getMsg(); }
/** * A null {@link ShellProcess} will not throw an exception. */ @Test public void handleLog_nullProcess() { ShellMsg msg = mockMsg(); ShellProcess process = mockProcess(); logHandler.setUpContext(DefaultShellLogHandlerTest.class, process, null); logHandler.log(msg); verify(msg).getMsg(); }
@Before public void setUp() { logHandler = new DefaultShellLogHandler(); }
this.log = getLogger(null);
/** * If both {@link ShellMsg} and {@link ShellProcess} are provided, both * will be used to build the log message. */ @Test public void handleLog_valid() { ShellMsg msg = mockMsg(); ShellProcess process = mockProcess(); logHandler.setUpContext(DefaultShellLogHandlerTest.class, process, null); logHandler.log(msg); verify(msg).getMsg(); verify(process).getProcessInfoString(); } }
/** * Calling setUpContext is optional. */ @Test public void setUpContext_optional() { ShellMsg msg = mockMsg(); logHandler.log(msg); verify(msg).getMsg(); }
public static ShellLogHandler getLogHandler(Map stormConf) { if (stormConf == null) { throw new IllegalArgumentException("Config is required"); } String logHandlerClassName = null; if (stormConf.containsKey(Config.TOPOLOGY_MULTILANG_LOG_HANDLER)) { try { logHandlerClassName = stormConf.get(Config.TOPOLOGY_MULTILANG_LOG_HANDLER).toString(); return (ShellLogHandler) Class.forName(logHandlerClassName).newInstance(); } catch (ClassCastException | InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new RuntimeException("Error loading ShellLogHandler " + logHandlerClassName, e); } } return new DefaultShellLogHandler(); } }
/** * This default implementation saves the {@link ShellProcess} so it can * output the process info string later. * @see {@link ShellLogHandler#setUpContext} * * @param ownerCls * - the class which instantiated this ShellLogHandler. * @param process * - the current {@link ShellProcess}. * @param context * - the current {@link TopologyContext}. */ public void setUpContext(final Class<?> ownerCls, final ShellProcess process, final TopologyContext context) { this.log = getLogger(ownerCls); this.process = process; // context is not used by the default implementation, but is included // in the interface in case it is useful to subclasses }
this.log = getLogger(null);