com.spotify.logging.LoggingConfigurator Java Examples
The following examples show how to use
com.spotify.logging.LoggingConfigurator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SentryTest.java From helios with Apache License 2.0 | 6 votes |
@Test public void testSentryAppender() throws Exception { // start our UDP server which will receive sentry messages final UdpServer udpServer = new UdpServer(sentryPort); // turn on logging which enables the sentry appender final LoggingConfig config = new LoggingConfig(0, true, null, false); ServiceMain.setupLogging(config, testDsn); // log a message at error level so sentry appender sends it to UDP server log.error("Ignore test message printed by Helios SentryTest"); // be nice and turn logging back off LoggingConfigurator.configureNoLogging(); // make sure we got the message as expected, note that getMessage is a blocking method final String message = udpServer.getMessage(); assertTrue("Expected message beginning with 'Sentry', instead got " + message, message.startsWith("Sentry")); }
Example #2
Source File: SpotifyInternalAppender.java From logging-java with Apache License 2.0 | 6 votes |
@Override public void start() { Preconditions.checkState(serviceName != null, "serviceName must be configured"); // set up some defaults setFacility("LOCAL0"); // our internal syslog-ng configuration splits logs up based on service name, and expects the // format below. String serviceAndPid = String.format("%s[%s]", serviceName, getMyPid()); setSuffixPattern(serviceAndPid + ": " + LoggingConfigurator.ReplaceNewLines.getMsgPattern(this.replaceNewLines)); setStackTracePattern(serviceAndPid + ": " + CoreConstants.TAB); if (getSyslogHost() == null) { setSyslogHost(System.getenv(LoggingConfigurator.SPOTIFY_SYSLOG_HOST)); } checkSetPort(System.getenv(LoggingConfigurator.SPOTIFY_SYSLOG_PORT)); super.start(); }
Example #3
Source File: SimpleSyslogExample.java From logging-java with Apache License 2.0 | 6 votes |
public static void main(final String... args) { LoggingConfigurator.configureSyslogDefaults("example"); while (true) { // Should not be logged logger.trace("trace!"); // Should show up in syslog logger.debug("debug!"); logger.info("info!"); logger.warn("warn!"); logger.error("error!", new Exception("failure")); try { Thread.sleep(1000); } catch (InterruptedException ignore) { } } }
Example #4
Source File: SimpleConsoleExample.java From logging-java with Apache License 2.0 | 6 votes |
public static void main(final String... args) { LoggingConfigurator.configureDefaults("example", INFO, LoggingConfigurator.ReplaceNewLines.ON); while (true) { // Should not be logged logger.trace("trace!"); // Should show up in console logger.debug("debug!"); logger.info("info!"); logger.warn("warn!"); logger.error("\nerror!\n", new Exception("failure")); try { Thread.sleep(1000); } catch (InterruptedException ignore) { } } }
Example #5
Source File: ServiceMain.java From helios with Apache License 2.0 | 5 votes |
protected static void setupLogging(LoggingConfig config, String sentryDsn) { if (config.getNoLogSetup()) { return; } // Hijack JUL SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); final int verbose = config.getVerbosity(); final Level level = get(asList(INFO, DEBUG, ALL), verbose, ALL); final File logconfig = config.getConfigFile(); if (logconfig != null) { LoggingConfigurator.configure(logconfig); } else { if (config.isSyslog()) { LoggingConfigurator.configureSyslogDefaults("helios", level); } else { LoggingConfigurator.configureDefaults("helios", level); } if (!Strings.isNullOrEmpty(sentryDsn)) { LoggingConfigurator.addSentryAppender(sentryDsn); } } }
Example #6
Source File: SpotifyInternalAppender.java From logging-java with Apache License 2.0 | 5 votes |
private void checkSetPort(String environmentValue) { if (environmentValue == null || portConfigured) { return; } try { setPort(Integer.parseInt(environmentValue)); } catch (NumberFormatException e) { throw new IllegalArgumentException( "unable to parse value for \"" + LoggingConfigurator.SPOTIFY_SYSLOG_PORT + "\" (" + environmentValue + ") as an int", e); } }
Example #7
Source File: SpotifyInternalAppenderTest.java From logging-java with Apache License 2.0 | 5 votes |
@Test public void shouldUseEnvironmentVariableForPortByDefault() throws Exception { environmentVariables.set(LoggingConfigurator.SPOTIFY_SYSLOG_PORT, "7642"); appender.start(); assertThat(appender.getPort(), is(7642)); }
Example #8
Source File: SpotifyInternalAppenderTest.java From logging-java with Apache License 2.0 | 5 votes |
@Test public void shouldFailForNonIntPort() throws Exception { environmentVariables.set(LoggingConfigurator.SPOTIFY_SYSLOG_PORT, "76424356436234623462345"); thrown.expect(IllegalArgumentException.class); appender.start(); }
Example #9
Source File: SpotifyInternalAppenderTest.java From logging-java with Apache License 2.0 | 5 votes |
@Test public void shouldSupportOverridingPort() throws Exception { environmentVariables.set(LoggingConfigurator.SPOTIFY_SYSLOG_PORT, "7642"); appender.setPort(9878); appender.start(); assertThat(appender.getPort(), is(9878)); }
Example #10
Source File: SpotifyInternalAppenderTest.java From logging-java with Apache License 2.0 | 5 votes |
@Test public void shouldSupportOverridingPortTo514() throws Exception { environmentVariables.set(LoggingConfigurator.SPOTIFY_SYSLOG_PORT, "7642"); appender.setPort(514); appender.start(); assertThat(appender.getPort(), is(514)); }
Example #11
Source File: GoogleClientPullBenchmark.java From async-google-pubsub-client with Apache License 2.0 | 4 votes |
public static void main(final String... args) throws IOException, ExecutionException, InterruptedException { final String project = Util.defaultProject(); GoogleCredential credential; // Use credentials from file if available try { credential = GoogleCredential .fromStream(new FileInputStream("credentials.json")) .createScoped(PubsubScopes.all()); } catch (IOException e) { credential = GoogleCredential.getApplicationDefault() .createScoped(PubsubScopes.all()); } LoggingConfigurator.configureDefaults("benchmark", WARN); final String subscription = System.getenv("GOOGLE_PUBSUB_SUBSCRIPTION"); if (subscription == null) { System.err.println("Please specify a subscription using the GOOGLE_PUBSUB_SUBSCRIPTION environment variable."); System.exit(1); } System.out.println("Consuming from GOOGLE_PUBSUB_SUBSCRIPTION='" + subscription + "'"); final Pubsub pubsub = new Pubsub.Builder(Utils.getDefaultTransport(), Utils.getDefaultJsonFactory(), credential) .setApplicationName("pull-benchmark") .build(); final Pubsub.Projects.Subscriptions subscriptions = pubsub.projects().subscriptions(); final String canonicalSubscription = Subscription.canonicalSubscription(project, subscription); final ProgressMeter meter = new ProgressMeter(); final ProgressMeter.Metric receives = meter.group("operations").metric("receives", "messages"); final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()); // Pull concurrently for (int i = 0; i < PULLER_CONCURRENCY; i++) { pull(subscriptions, canonicalSubscription, receives, executor); } }
Example #12
Source File: PublisherBenchmark.java From async-google-pubsub-client with Apache License 2.0 | 4 votes |
public static void main(final String... args) throws IOException { final String project = Util.defaultProject(); GoogleCredential credential; // Use credentials from file if available try { credential = GoogleCredential .fromStream(new FileInputStream("credentials.json")) .createScoped(PubsubScopes.all()); } catch (IOException e) { credential = GoogleCredential.getApplicationDefault() .createScoped(PubsubScopes.all()); } final Pubsub pubsub = Pubsub.builder() .credential(credential) .compressionLevel(Deflater.BEST_SPEED) .enabledCipherSuites(nonGcmCiphers()) .build(); final Publisher publisher = Publisher.builder() .pubsub(pubsub) .concurrency(128) .project(project) .build(); LoggingConfigurator.configureDefaults("benchmark", WARN); final String topicPrefix = TEST_NAME_PREFIX + ThreadLocalRandom.current().nextInt(); final List<String> topics = IntStream.range(0, 100) .mapToObj(i -> topicPrefix + "-" + i) .collect(toList()); topics.stream() .map(topic -> pubsub.createTopic(project, topic)) .collect(toList()) .forEach(Futures::getUnchecked); final List<Message> messages = IntStream.range(0, 1000) .mapToObj(i -> { final StringBuilder s = new StringBuilder(); while (s.length() < MESSAGE_SIZE) { s.append(ThreadLocalRandom.current().nextInt()); } return Message.ofEncoded(s.toString()); }) .collect(toList()); final ProgressMeter meter = new ProgressMeter(); final ProgressMeter.Metric requests = meter.group("operations").metric("publishes", "messages"); for (int i = 0; i < 100000; i++) { benchSend(publisher, messages, topics, requests); } }
Example #13
Source File: EndToEndBenchmark.java From async-google-pubsub-client with Apache License 2.0 | 4 votes |
public static void main(final String... args) throws IOException, ExecutionException, InterruptedException { final String project = Util.defaultProject(); GoogleCredential credential; // Use credentials from file if available try { credential = GoogleCredential .fromStream(new FileInputStream("credentials.json")) .createScoped(PubsubScopes.all()); } catch (IOException e) { credential = GoogleCredential.getApplicationDefault() .createScoped(PubsubScopes.all()); } final Pubsub pubsub = Pubsub.builder() .credential(credential) .compressionLevel(Deflater.BEST_SPEED) .enabledCipherSuites(nonGcmCiphers()) .build(); final Publisher publisher = Publisher.builder() .pubsub(pubsub) .concurrency(PUBLISHER_CONCURRENCY) .project(project) .build(); LoggingConfigurator.configureDefaults("benchmark", WARN); final String topic = "test-" + Long.toHexString(ThreadLocalRandom.current().nextLong()); final String subscription = "test-" + Long.toHexString(ThreadLocalRandom.current().nextLong()); pubsub.createTopic(project, topic).get(); pubsub.createSubscription(project, subscription, topic).get(); final List<String> payloads = IntStream.range(0, 1024) .mapToObj(i -> { final StringBuilder s = new StringBuilder(); while (s.length() < MESSAGE_SIZE) { s.append(ThreadLocalRandom.current().nextInt()); } return Message.encode(s.toString()); }) .collect(toList()); final int payloadIxMask = 1024 - 1; final Supplier<Message> generator = () -> Message.builder() .data(payloads.get(ThreadLocalRandom.current().nextInt() & payloadIxMask)) .putAttribute("ts", Long.toHexString(System.nanoTime())) .build(); final ProgressMeter meter = new ProgressMeter(); final ProgressMeter.Metric publishes = meter.group("operations").metric("publishes", "messages"); final ProgressMeter.Metric receives = meter.group("operations").metric("receives", "messages"); for (int i = 0; i < 100000; i++) { publish(publisher, generator, topic, publishes); } // Pull concurrently and (asynchronously) publish a new message for every message received for (int i = 0; i < PULLER_CONCURRENCY; i++) { pull(project, pubsub, subscription, receives, () -> publish(publisher, generator, topic, publishes)); } }
Example #14
Source File: PullerBenchmark.java From async-google-pubsub-client with Apache License 2.0 | 4 votes |
public static void main(final String... args) throws IOException, ExecutionException, InterruptedException { final String project = Util.defaultProject(); GoogleCredential credential; // Use credentials from file if available try { credential = GoogleCredential .fromStream(new FileInputStream("credentials.json")) .createScoped(PubsubScopes.all()); } catch (IOException e) { credential = GoogleCredential.getApplicationDefault() .createScoped(PubsubScopes.all()); } final Pubsub pubsub = Pubsub.builder() .credential(credential) .compressionLevel(Deflater.BEST_SPEED) .enabledCipherSuites(Util.nonGcmCiphers()) .build(); LoggingConfigurator.configureDefaults("benchmark", WARN); final String subscription = System.getenv("GOOGLE_PUBSUB_SUBSCRIPTION"); if (subscription == null) { System.err.println("Please specify a subscription using the GOOGLE_PUBSUB_SUBSCRIPTION environment variable."); System.exit(1); } System.out.println("Consuming from GOOGLE_PUBSUB_SUBSCRIPTION='" + subscription + "'"); final ProgressMeter meter = new ProgressMeter(); final ProgressMeter.Metric receives = meter.group("operations").metric("receives", "messages"); final Puller puller = Puller.builder() .pubsub(pubsub) .batchSize(1000) .concurrency(PULLER_CONCURRENCY) .project(project) .subscription(subscription) .messageHandler(new Handler(receives)) .build(); while (true) { Thread.sleep(1000); System.out.println("outstanding messages: " + puller.outstandingMessages()); System.out.println("outstanding requests: " + puller.outstandingRequests()); } }
Example #15
Source File: SpotifyInternalAppender.java From logging-java with Apache License 2.0 | 4 votes |
public void setReplaceNewLines(LoggingConfigurator.ReplaceNewLines replaceNewLines) { this.replaceNewLines = replaceNewLines; }
Example #16
Source File: SpotifyInternalAppenderTest.java From logging-java with Apache License 2.0 | 4 votes |
private void setSyslogHostEnvVar() { // this must be a valid host name that can be looked up anywhere environmentVariables.set(LoggingConfigurator.SPOTIFY_SYSLOG_HOST, "www.spotify.com"); }