String getPrefixPattern() { return "%syslogStart{" + getFacility() + "}%nopex{}"; }
protected static void doMain(Class<? extends SimpleSocketServer> serverClass, String argv[]) throws Exception { int port = -1; if (argv.length == 2) { port = parsePortNumber(argv[0]); } else { usage("Wrong number of arguments."); } String configFile = argv[1]; LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); configureLC(lc, configFile); SimpleSocketServer sss = new SimpleSocketServer(lc, port); sss.start(); }
/** * {@inheritDoc} */ public void run() { try { LoggerContext lc = (LoggerContext) getContext(); while (!Thread.currentThread().isInterrupted()) { SocketConnector connector = createConnector(address, port, 0, reconnectionDelay); connectorTask = activateConnector(connector); if (connectorTask == null) { break; } socket = waitForConnectorToReturnASocket(); if (socket == null) break; dispatchEvents(lc); } } catch (InterruptedException ex) { assert true; // ok... we'll exit now } addInfo("shutting down"); }
/** * {@inheritDoc} */ public final void start() { if (isStarted()) return; if (getContext() == null) { throw new IllegalStateException("context not set"); } if (shouldStart()) { getContext().getScheduledExecutorService().execute(getRunnableTask()); started = true; } }
/** * {@inheritDoc} */ @Override protected boolean shouldStart() { try { SSLContext sslContext = getSsl().createContext(this); SSLParametersConfiguration parameters = getSsl().getParameters(); parameters.setContext(getContext()); socketFactory = new ConfigurableSSLSocketFactory(parameters, sslContext.getSocketFactory()); return super.shouldStart(); } catch (Exception ex) { addError(ex.getMessage(), ex); return false; } }
private void setupStackTraceLayout() { stackTraceLayout.getInstanceConverterMap().put("syslogStart", SyslogStartConverter.class.getName()); stackTraceLayout.setPattern(getPrefixPattern() + stackTracePattern); stackTraceLayout.setContext(getContext()); stackTraceLayout.start(); }
@Override public SyslogOutputStream createOutputStream() throws SocketException, UnknownHostException { return new SyslogOutputStream(getSyslogHost(), getPort()); }
private SocketConnector createConnector(InetAddress address, int port, int initialDelay, int retryDelay) { SocketConnector connector = newConnector(address, port, initialDelay, retryDelay); connector.setExceptionHandler(this); connector.setSocketFactory(getSocketFactory()); return connector; }
@Override protected Layout<ILoggingEvent> makeSubjectLayout(String subjectStr) { if (subjectStr == null) { subjectStr = DEFAULT_SUBJECT_PATTERN; } PatternLayout pl = new PatternLayout(); pl.setContext(getContext()); pl.setPattern(subjectStr); // we don't want a ThrowableInformationConverter appended // to the end of the converter chain // This fixes issue LBCLASSIC-67 pl.setPostCompileProcessor(null); pl.start(); return pl; }
static int parsePortNumber(String portStr) { try { return Integer.parseInt(portStr); } catch (java.lang.NumberFormatException e) { e.printStackTrace(); usage("Could not interpret port number [" + portStr + "]."); // we won't get here return -1; } }
public static void main(String argv[]) throws Exception { doMain(SimpleSSLSocketServer.class, argv); }
public static void main(String argv[]) throws Exception { doMain(SimpleSocketServer.class, argv); }
public void start() { super.start(); setupStackTraceLayout(); }
/** * {@inheritDoc} */ protected boolean shouldStart() { int errorCount = 0; if (port == 0) { errorCount++; addError("No port was configured for receiver. " + "For more information, please visit http://logback.qos.ch/codes.html#receiver_no_port"); } if (remoteHost == null) { errorCount++; addError("No host name or address was configured for receiver. " + "For more information, please visit http://logback.qos.ch/codes.html#receiver_no_host"); } if (reconnectionDelay == 0) { reconnectionDelay = AbstractSocketAppender.DEFAULT_RECONNECTION_DELAY; } if (errorCount == 0) { try { address = InetAddress.getByName(remoteHost); } catch (UnknownHostException ex) { addError("unknown host: " + remoteHost); errorCount++; } } if (errorCount == 0) { receiverId = "receiver " + remoteHost + ":" + port + ": "; } return errorCount == 0; }
private Future<Socket> activateConnector(SocketConnector connector) { try { return getContext().getScheduledExecutorService().submit(connector); } catch (RejectedExecutionException ex) { return null; } }
@Override public void end(InterpretationContext ic, String name) throws ActionException { if (inError) return; ic.getContext().register(receiver); receiver.start(); Object o = ic.peekObject(); if (o != receiver) { addWarn("The object at the of the stack is not the remote " + "pushed earlier."); } else { ic.popObject(); } }
public Layout<ILoggingEvent> buildLayout() { PatternLayout layout = new PatternLayout(); layout.getInstanceConverterMap().put("syslogStart", SyslogStartConverter.class.getName()); if (suffixPattern == null) { suffixPattern = DEFAULT_SUFFIX_PATTERN; } layout.setPattern(getPrefixPattern() + suffixPattern); layout.setContext(getContext()); layout.start(); return layout; }
public void start() { if (eventEvaluator == null) { OnErrorEvaluator onError = new OnErrorEvaluator(); onError.setContext(getContext()); onError.setName("onError"); onError.start(); this.eventEvaluator = onError; } super.start(); }