@Test public void configureDestination_shouldStoreStackTracesInTheFileSystem_whenLoggingToAStreamAndAStacktraceStoragePathHasBeenExplicitlyProvided() throws Exception { Path expectedStackTraceStoragePath = tempFiles.createTempDirectory(); InfrastructureFactory factory = new InfrastructureFactory( Optional.empty(), Optional.of(System.err), Optional.of(true), Optional.of(expectedStackTraceStoragePath), SAMPLE_CONTEXT_SUPPLIER, SAMPLE_ERROR_HANDLER); StackTraceProcessor stackTraceProcessor = factory.<TestMessages>configureDestination().getStackTraceProcessor(); assertThat(stackTraceProcessor, instanceOf(FilesystemStackTraceProcessor.class)); FilesystemStackTraceProcessor fs = (FilesystemStackTraceProcessor) stackTraceProcessor; assertSame(expectedStackTraceStoragePath, fs.getDestination()); }
public <T extends Enum<T> & LogMessage> Destination<T> configureDestination() throws UncheckedIOException { try { StackTraceProcessor stackTraceProcessor = this.configureStackTraceProcessor(); if (logfilePath.isPresent()) { if (!Files.isSymbolicLink(logfilePath.get().getParent())) { Files.createDirectories(logfilePath.get().getParent()); } FileChannelProvider provider = new FileChannelProvider(logfilePath.get()); ActiveRotationRegistry registry = ActiveRotationRegistry.getSingletonInstance(); return registry.add(new PathDestination<>(provider, stackTraceProcessor, registry)); } return new OutputStreamDestination<>(loggerOutput.orElse(System.out), stackTraceProcessor); } catch (IOException e) { throw new UncheckedIOException(e); } }
InfrastructureFactory { public <T extends Enum<T> & LogMessage> Destination<T> configureDestination() throws UncheckedIOException { try { StackTraceProcessor stackTraceProcessor = this.configureStackTraceProcessor(); if (logfilePath.isPresent()) { if (!Files.isSymbolicLink(logfilePath.get().getParent())) { Files.createDirectories(logfilePath.get().getParent()); } FileChannelProvider provider = new FileChannelProvider(logfilePath.get()); ActiveRotationRegistry registry = ActiveRotationRegistry.getSingletonInstance(); return registry.add(new PathDestination<>(provider, stackTraceProcessor, registry)); } return new OutputStreamDestination<>(loggerOutput.orElse(System.out), stackTraceProcessor); } catch (IOException e) { throw new UncheckedIOException(e); } } }
InfrastructureFactory { public <T extends Enum<T> & LogMessage> Destination<T> configureDestination() throws UncheckedIOException { try { StackTraceProcessor stackTraceProcessor = this.configureStackTraceProcessor(); if (logfilePath.isPresent()) { if (!Files.isSymbolicLink(logfilePath.get().getParent())) { Files.createDirectories(logfilePath.get().getParent()); } FileChannelProvider provider = new FileChannelProvider(logfilePath.get()); ActiveRotationRegistry registry = ActiveRotationRegistry.getSingletonInstance(); return registry.add(new PathDestination<>(provider, stackTraceProcessor, registry)); } return new OutputStreamDestination<>(loggerOutput.orElse(System.out), stackTraceProcessor); } catch (IOException e) { throw new UncheckedIOException(e); } } InfrastructureFactory(Optional<Path> logfilePath, Optional<PrintStream> loggerOutput, Optional<Boolean> storeStackTracesInFilesystem, Optional<Path> stackTraceStoragePath, Optional<DiagnosticContextSupplier> correlationIdSupplier, Optional<Consumer<Throwable>> errorHandler); }
InfrastructureFactory { public <T extends Enum<T> & LogMessage> Destination<T> configureDestination() throws UncheckedIOException { try { StackTraceProcessor stackTraceProcessor = this.configureStackTraceProcessor(); if (logfilePath.isPresent()) { if (!Files.isSymbolicLink(logfilePath.get().getParent())) { Files.createDirectories(logfilePath.get().getParent()); } FileChannelProvider provider = new FileChannelProvider(logfilePath.get()); ActiveRotationRegistry registry = ActiveRotationRegistry.getSingletonInstance(); return registry.add(new PathDestination<>(provider, stackTraceProcessor, registry)); } return new OutputStreamDestination<>(loggerOutput.orElse(System.out), stackTraceProcessor); } catch (IOException e) { throw new UncheckedIOException(e); } } InfrastructureFactory(Optional<Path> logfilePath, Optional<PrintStream> loggerOutput, Optional<Boolean> storeStackTracesInFilesystem, Optional<Path> stackTraceStoragePath, Optional<DiagnosticContextSupplier> correlationIdSupplier, Optional<Consumer<Throwable>> errorHandler); Destination<T> configureDestination(); Consumer<Throwable> configureErrorHandler(); DiagnosticContextSupplier configureContextSupplier(); Optional<Path> getLogfilePath(); Optional<PrintStream> getLoggerOutput(); Optional<Boolean> getStoreStackTracesInFilesystem(); Optional<Path> getStackTraceStoragePath(); Optional<DiagnosticContextSupplier> getContextSupplier(); Optional<Consumer<Throwable>> getErrorHandler(); }
InfrastructureFactory { public <T extends Enum<T> & LogMessage> Destination<T> configureDestination() throws UncheckedIOException { try { StackTraceProcessor stackTraceProcessor = this.configureStackTraceProcessor(); if (logfilePath.isPresent()) { if (!Files.isSymbolicLink(logfilePath.get().getParent())) { Files.createDirectories(logfilePath.get().getParent()); } FileChannelProvider provider = new FileChannelProvider(logfilePath.get()); ActiveRotationRegistry registry = ActiveRotationRegistry.getSingletonInstance(); return registry.add(new PathDestination<>(provider, stackTraceProcessor, registry)); } return new OutputStreamDestination<>(loggerOutput.orElse(System.out), stackTraceProcessor); } catch (IOException e) { throw new UncheckedIOException(e); } } InfrastructureFactory(Optional<Path> logfilePath, Optional<PrintStream> loggerOutput, Optional<Boolean> storeStackTracesInFilesystem, Optional<Path> stackTraceStoragePath, Optional<DiagnosticContextSupplier> correlationIdSupplier, Optional<Consumer<Throwable>> errorHandler); Destination<T> configureDestination(); Consumer<Throwable> configureErrorHandler(); DiagnosticContextSupplier configureContextSupplier(); Optional<Path> getLogfilePath(); Optional<PrintStream> getLoggerOutput(); Optional<Boolean> getStoreStackTracesInFilesystem(); Optional<Path> getStackTraceStoragePath(); Optional<DiagnosticContextSupplier> getContextSupplier(); Optional<Consumer<Throwable>> getErrorHandler(); static final Consumer<Throwable> DEFAULT_ERROR_HANDLER; static final DiagnosticContextSupplier EMPTY_CONTEXT_SUPPLIER; }