├── .java-version ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── LICENSE_HEADER └── release.gradle ├── logback-audio ├── src │ ├── test │ │ ├── resources │ │ │ ├── bark.ogg │ │ │ ├── drip.ogg │ │ │ ├── glass.ogg │ │ │ ├── sample.ogg │ │ │ ├── message.ogg │ │ │ ├── logback-with-converter.xml │ │ │ └── logback-with-marker-appender.xml │ │ └── java │ │ │ └── com │ │ │ └── tersesystems │ │ │ └── logback │ │ │ └── audio │ │ │ └── TestNested.java │ └── main │ │ └── java │ │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── audio │ │ ├── Player.java │ │ ├── PlayerAttachable.java │ │ ├── URLPlayer.java │ │ ├── SystemPlayer.java │ │ ├── PlayerException.java │ │ ├── AudioAppender.java │ │ ├── AudioMarkerAppender.java │ │ ├── AudioMarker.java │ │ ├── PlayerConverter.java │ │ ├── FilePlayer.java │ │ ├── ResourcePlayer.java │ │ ├── PlayMethods.java │ │ └── SimplePlayer.java ├── gradle.properties └── logback-audio.gradle ├── logback-exception-mapping-providers ├── src │ └── test │ │ ├── resources │ │ ├── logback.conf │ │ └── logback-with-exception-mapping.xml │ │ └── java │ │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── exceptionmapping │ │ └── json │ │ ├── MySpecialException.java │ │ └── TypesafeConfigMappingsActionTest.java ├── gradle.properties └── logback-exception-mapping-providers.gradle ├── logback-typesafe-config ├── src │ ├── test │ │ ├── resources │ │ │ ├── logback-test.conf │ │ │ └── typesafeconfig │ │ │ │ ├── config-with-local.xml │ │ │ │ ├── config-with-default.xml │ │ │ │ └── config-with-context.xml │ │ └── java │ │ │ └── com │ │ │ └── tersesystems │ │ │ └── logback │ │ │ └── typesafeconfig │ │ │ └── ConfigListConverterTest.java │ └── main │ │ └── java │ │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── typesafeconfig │ │ ├── ConfigConstants.java │ │ └── ConfigConversion.java ├── gradle.properties └── logback-typesafe-config.gradle ├── logback-honeycomb-client ├── logback-honeycomb-client.gradle ├── gradle.properties └── src │ └── main │ └── java │ └── com │ └── tersesystems │ └── logback │ └── honeycomb │ └── client │ ├── HoneycombClientService.java │ ├── HoneycombHeaders.java │ ├── HoneycombRequest.java │ ├── HoneycombClient.java │ └── HoneycombResponse.java ├── logback-budget ├── gradle.properties ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── tersesystems │ │ │ └── logback │ │ │ └── budget │ │ │ ├── BudgetRuleAttachable.java │ │ │ └── BudgetRule.java │ └── test │ │ ├── java │ │ └── com.tersesystems.logback.budget │ │ │ ├── BudgetTurboFilterTest.java │ │ │ └── BudgetEvaluatorTest.java │ │ └── resources │ │ ├── logback-turbofilter.xml │ │ └── logback-budget.xml └── logback-budget.gradle ├── logback-classic ├── gradle.properties ├── src │ ├── test │ │ ├── java │ │ │ └── com │ │ │ │ └── tersesystems │ │ │ │ └── logback │ │ │ │ └── classic │ │ │ │ ├── SetLoggerLevelsActionTest.java │ │ │ │ ├── ChangeLogLevelTest.java │ │ │ │ ├── CorrelationIdMarker.java │ │ │ │ ├── EnabledFilterTest.java │ │ │ │ ├── TerseHighlightConverterTest.java │ │ │ │ └── UtilsTest.java │ │ └── resources │ │ │ ├── logback-tapfilter.xml │ │ │ └── logback-tapfilter-correlation.xml │ └── main │ │ └── java │ │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── classic │ │ ├── StartTimeSupplier.java │ │ ├── NanoTimeSupplier.java │ │ ├── sift │ │ ├── DiscriminatingValue.java │ │ ├── DiscriminatingMarkerFactory.java │ │ └── DiscriminatingMarker.java │ │ ├── IContainerLoggingEvent.java │ │ ├── TimeSinceEpochConverter.java │ │ ├── ILoggingEventFactory.java │ │ ├── NanoTimeConverter.java │ │ ├── StartTimeConverter.java │ │ ├── LoggerDecider.java │ │ ├── FormatParamsDecider.java │ │ ├── MarkerLoggerDecider.java │ │ ├── ContainerEventAppender.java │ │ ├── LoggingEventFactory.java │ │ ├── NanoTimeMarker.java │ │ ├── StartTimeMarker.java │ │ ├── TurboFilterDecider.java │ │ ├── functional │ │ ├── RootLoggerSupplier.java │ │ ├── GetSiftedAppenderFunction.java │ │ └── GetAppenderFunction.java │ │ ├── encoder │ │ └── PatternLayoutEncoder.java │ │ ├── NanoTimeComponentAppender.java │ │ ├── ContainerProxyLoggingEvent.java │ │ ├── SLF4JBridgeHandlerAction.java │ │ └── ChangeLogLevel.java └── logback-classic.gradle ├── logback-correlationid ├── src │ ├── test │ │ └── resources │ │ │ ├── spy.properties │ │ │ ├── logback-correlationid.xml │ │ │ └── logback-correlationid-tapfilter.xml │ └── main │ │ └── java │ │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── correlationid │ │ ├── CorrelationIdProvider.java │ │ ├── CorrelationIdMarker.java │ │ ├── CorrelationIdDecider.java │ │ └── CorrelationIdFilter.java ├── gradle.properties └── logback-correlationid.gradle ├── logback-turbomarker ├── gradle.properties ├── src │ ├── test │ │ ├── java │ │ │ └── com │ │ │ │ └── tersesystems │ │ │ │ └── logback │ │ │ │ └── turbomarker │ │ │ │ ├── ApplicationContext.java │ │ │ │ ├── UserMarker.java │ │ │ │ ├── UserMarkerFactory.java │ │ │ │ └── LDMarkerFactory.java │ │ └── resources │ │ │ └── logback-test.xml │ └── main │ │ └── java │ │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── turbomarker │ │ ├── TurboMarker.java │ │ ├── ContextAwareTurboFilterDecider.java │ │ ├── ContextDecider.java │ │ ├── LoggerContextDecider.java │ │ ├── MarkerContextDecider.java │ │ └── ContextAwareTurboMarker.java └── logback-turbomarker.gradle ├── logback-core ├── gradle.properties ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── tersesystems │ │ │ └── logback │ │ │ └── core │ │ │ ├── Component.java │ │ │ ├── ComponentContainer.java │ │ │ ├── EnabledFilter.java │ │ │ └── DefaultAppenderAttachable.java │ └── test │ │ ├── resources │ │ └── logback-with-composite-appender.xml │ │ └── java │ │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── core │ │ ├── TestAppender.java │ │ └── CompositeAppenderTest.java └── logback-core.gradle ├── logback-jdbc-appender ├── gradle.properties ├── logback-jdbc-appender.gradle └── src │ └── test │ └── resources │ ├── logback-reference.conf │ └── logback-test.xml ├── logback-tracing ├── gradle.properties ├── logback-tracing.gradle └── src │ └── main │ └── java │ └── com │ └── tersesystems │ └── logback │ └── tracing │ ├── Nullable.java │ ├── EventInfo.java │ ├── LinkInfo.java │ ├── LinkMarkerFactory.java │ ├── EventMarkerFactory.java │ └── SpanMarkerFactory.java ├── logback-compress-encoder ├── gradle.properties ├── logback-compress-encoder.gradle └── src │ └── test │ ├── resources │ └── logback-with-zstd-encoder.xml │ └── java │ └── com │ └── tersesystems │ └── logback │ └── compress │ └── Utils.java ├── logback-bytebuddy ├── gradle.properties └── src │ ├── test │ ├── resources │ │ ├── logback.conf │ │ └── logback-test.xml │ └── java │ │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── bytebuddy │ │ ├── ClassCalledByAgent.java │ │ ├── PreloadedInstrumentationExample.java │ │ └── AdviceConfigTest.java │ └── main │ └── java │ └── com │ └── tersesystems │ └── logback │ └── bytebuddy │ ├── impl │ ├── LoggerResolver.java │ ├── FixedLoggerResolver.java │ ├── DeclaringTypeLoggerResolver.java │ └── SafeArguments.java │ ├── MethodInfo.java │ └── MethodInfoLookup.java ├── logback-exception-mapping ├── gradle.properties ├── logback-exception-mapping.gradle └── src │ ├── main │ └── java │ │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── exceptionmapping │ │ ├── Constants.java │ │ ├── ExceptionMapping.java │ │ ├── FunctionExceptionMapping.java │ │ ├── KeyValueExceptionProperty.java │ │ ├── ExceptionHierarchyIterator.java │ │ ├── ExceptionCauseIterator.java │ │ ├── ExceptionMappingRegistry.java │ │ └── ExceptionProperty.java │ └── test │ ├── java │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── exceptionmapping │ │ ├── MyCustomException.java │ │ └── Thrower.java │ └── resources │ └── logback-test.xml ├── logback-honeycomb-appender ├── gradle.properties └── logback-honeycomb-appender.gradle ├── logback-uniqueid-appender ├── gradle.properties ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── tersesystems │ │ │ └── logback │ │ │ └── uniqueid │ │ │ ├── IdGenerator.java │ │ │ ├── UniqueIdProvider.java │ │ │ ├── TsidIdgenerator.java │ │ │ ├── KsuidSubsecondIdGenerator.java │ │ │ ├── UlidIdGenerator.java │ │ │ ├── UniqueIdConverter.java │ │ │ ├── FlakeIdGenerator.java │ │ │ ├── RandomUUIDIdGenerator.java │ │ │ └── UniqueIdComponentAppender.java │ └── test │ │ ├── resources │ │ └── logback-with-uniqueid-appender.xml │ │ └── java │ │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── uniqueid │ │ └── UniqueIdAppenderTest.java └── logback-uniqueid-appender.gradle ├── .gitignore ├── logback-postgresjson-appender ├── gradle.properties ├── src │ ├── test │ │ ├── resources │ │ │ └── db │ │ │ │ └── migration │ │ │ │ └── V1__logging_table.sql │ │ └── java │ │ │ └── com │ │ │ └── tersesystems │ │ │ └── logback │ │ │ └── postgresjson │ │ │ └── PostgresJsonAppenderTest.java │ └── main │ │ └── java │ │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── postgresjson │ │ └── PostgresJsonAppender.java └── logback-postgresjson-appender.gradle ├── logback-honeycomb-okhttp ├── gradle.properties ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── services │ │ │ └── com.tersesystems.logback.honeycomb.client.HoneycombClientService │ │ └── java │ │ └── com │ │ └── tersesystems │ │ └── logback │ │ └── honeycomb │ │ └── okhttp │ │ └── HoneycombOkHTTPClientService.java └── logback-honeycomb-okhttp.gradle ├── logback-censor ├── gradle.properties ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── tersesystems │ │ │ └── logback │ │ │ └── censor │ │ │ ├── CensorAttachable.java │ │ │ ├── Censor.java │ │ │ ├── CensorConstants.java │ │ │ ├── CensoringPrettyPrintingJsonGeneratorDecorator.java │ │ │ └── CensorContextAware.java │ └── test │ │ ├── java │ │ └── com │ │ │ └── tersesystems │ │ │ └── logback │ │ │ └── censor │ │ │ ├── TestAppender.java │ │ │ └── RegexCensorTest.java │ │ └── resources │ │ ├── test1.xml │ │ ├── test2.xml │ │ ├── test3.xml │ │ └── test4.xml └── logback-censor.gradle ├── LICENSE ├── version.properties ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── gradle.properties └── settings.gradle /.java-version: -------------------------------------------------------------------------------- 1 | 1.8 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tersesystems/terse-logback/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /logback-audio/src/test/resources/bark.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tersesystems/terse-logback/HEAD/logback-audio/src/test/resources/bark.ogg -------------------------------------------------------------------------------- /logback-audio/src/test/resources/drip.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tersesystems/terse-logback/HEAD/logback-audio/src/test/resources/drip.ogg -------------------------------------------------------------------------------- /logback-audio/src/test/resources/glass.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tersesystems/terse-logback/HEAD/logback-audio/src/test/resources/glass.ogg -------------------------------------------------------------------------------- /logback-audio/src/test/resources/sample.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tersesystems/terse-logback/HEAD/logback-audio/src/test/resources/sample.ogg -------------------------------------------------------------------------------- /logback-audio/src/test/resources/message.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tersesystems/terse-logback/HEAD/logback-audio/src/test/resources/message.ogg -------------------------------------------------------------------------------- /logback-exception-mapping-providers/src/test/resources/logback.conf: -------------------------------------------------------------------------------- 1 | levels { 2 | root = INFO 3 | } 4 | 5 | 6 | exceptionmappings { 7 | com.tersesystems.logback.exceptionmapping.json.MySpecialException: ["timestamp"] 8 | } -------------------------------------------------------------------------------- /logback-typesafe-config/src/test/resources/logback-test.conf: -------------------------------------------------------------------------------- 1 | levels { 2 | examples = "INFO" 3 | } 4 | 5 | some.random.path = "pathValue" 6 | 7 | local { 8 | localKey = "bar" 9 | } 10 | 11 | context { 12 | contextKey = "bar" 13 | } 14 | -------------------------------------------------------------------------------- /gradle/LICENSE_HEADER: -------------------------------------------------------------------------------- 1 | SPDX-License-Identifier: CC0-1.0 2 | 3 | Copyright ${copyrightYear} ${author}. 4 | 5 | Licensed under the CC0 Public Domain Dedication; 6 | You may obtain a copy of the License at 7 | 8 | http://creativecommons.org/publicdomain/zero/1.0/ 9 | 10 | -------------------------------------------------------------------------------- /logback-honeycomb-client/logback-honeycomb-client.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | -------------------------------------------------------------------------------- /logback-budget/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Budget -------------------------------------------------------------------------------- /logback-audio/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Audio Markers -------------------------------------------------------------------------------- /logback-classic/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Classic -------------------------------------------------------------------------------- /logback-correlationid/src/test/resources/spy.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | driverlist=org.h2.Driver -------------------------------------------------------------------------------- /logback-turbomarker/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback TurboMarker -------------------------------------------------------------------------------- /logback-core/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Core (code only) Library -------------------------------------------------------------------------------- /logback-jdbc-appender/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback JDBC Appender -------------------------------------------------------------------------------- /logback-tracing/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Honeycomb Tracing -------------------------------------------------------------------------------- /logback-compress-encoder/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Compress Encoder -------------------------------------------------------------------------------- /logback-bytebuddy/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback ByteBuddy Instrumentation -------------------------------------------------------------------------------- /logback-bytebuddy/src/test/resources/logback.conf: -------------------------------------------------------------------------------- 1 | logback.bytebuddy { 2 | service-name = "example-app" 3 | 4 | tracing { 5 | "com.tersesystems.logback.bytebuddy.ClassCalledByAgent" = [ 6 | "printStatement", 7 | "printArgument", 8 | "throwException", 9 | ] 10 | 11 | "java.lang.Thread" = [ 12 | "run" 13 | ] 14 | } 15 | } -------------------------------------------------------------------------------- /logback-correlationid/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Correlation ID Utilities -------------------------------------------------------------------------------- /logback-exception-mapping/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Exception Mapping -------------------------------------------------------------------------------- /logback-honeycomb-appender/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Honeycomb Appender -------------------------------------------------------------------------------- /logback-honeycomb-client/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Honeycomb Client API -------------------------------------------------------------------------------- /logback-uniqueid-appender/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Unique ID Appender -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | 4 | logback-sigar/native/ 5 | 6 | # Ignore Gradle build output directory 7 | build 8 | target/ 9 | 10 | site/ 11 | 12 | .idea 13 | log/ 14 | 15 | out/ 16 | logback-example/log/* 17 | 18 | .classpath 19 | .project 20 | .settings 21 | .vscode/ 22 | bin/ 23 | *.iml 24 | *.ipr 25 | *.iws 26 | -------------------------------------------------------------------------------- /logback-postgresjson-appender/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Postgres JSON Appender -------------------------------------------------------------------------------- /logback-exception-mapping-providers/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Extra exception mapping providers -------------------------------------------------------------------------------- /logback-typesafe-config/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback using Typesafe Config for configuration -------------------------------------------------------------------------------- /logback-honeycomb-okhttp/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Honeycomb Client Implementation using OKHTTP -------------------------------------------------------------------------------- /logback-censor/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | project_description = Logback Censor Project (regular esxpression and Jackson JSON filtering) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | License 2 | ------- 3 | Written in 2019 by Will Sargent will@tersesystems.com 4 | To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. 5 | You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see -------------------------------------------------------------------------------- /logback-exception-mapping/logback-exception-mapping.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | plugins { 12 | id 'java-library' 13 | } 14 | 15 | dependencies { 16 | api project(':logback-classic') 17 | } -------------------------------------------------------------------------------- /version.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | #Version of the produced binaries. This file is intended to be checked-in. 13 | #It will be automatically bumped by release automation. 14 | version=1.2.* 15 | 16 | -------------------------------------------------------------------------------- /logback-classic/src/test/java/com/tersesystems/logback/classic/SetLoggerLevelsActionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | public class SetLoggerLevelsActionTest {} 14 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/Player.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | /** This can play audio sounds. */ 14 | public interface Player { 15 | void play(); 16 | } 17 | -------------------------------------------------------------------------------- /logback-uniqueid-appender/src/main/java/com/tersesystems/logback/uniqueid/IdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.uniqueid; 12 | 13 | public interface IdGenerator { 14 | String generateId(); 15 | } 16 | -------------------------------------------------------------------------------- /logback-censor/src/main/java/com/tersesystems/logback/censor/CensorAttachable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.censor; 12 | 13 | public interface CensorAttachable { 14 | void addCensor(CensorContextAware censor); 15 | } 16 | -------------------------------------------------------------------------------- /logback-typesafe-config/logback-typesafe-config.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | plugins { 12 | id 'java-library' 13 | } 14 | 15 | dependencies { 16 | api "ch.qos.logback:logback-classic:$logbackVersion" 17 | api "com.typesafe:config:$configVersion" 18 | } 19 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/PlayerAttachable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | public interface PlayerAttachable { 14 | void addPlayer(Player player); 15 | 16 | void clearAllPlayers(); 17 | } 18 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/StartTimeSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import java.time.Instant; 14 | 15 | public interface StartTimeSupplier { 16 | Instant getStartTime(); 17 | } 18 | -------------------------------------------------------------------------------- /logback-core/src/main/java/com/tersesystems/logback/core/Component.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.core; 13 | 14 | /** A marker interface to let the caller know this can be placed in a ContainerComponent. */ 15 | public interface Component {} 16 | -------------------------------------------------------------------------------- /logback-classic/logback-classic.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | plugins { 13 | id 'java-library' 14 | } 15 | 16 | dependencies { 17 | api project(':logback-core') 18 | api "org.slf4j:jul-to-slf4j:$slf4jVersion" 19 | api "ch.qos.logback:logback-classic:$logbackVersion" 20 | } -------------------------------------------------------------------------------- /logback-budget/src/main/java/com/tersesystems/logback/budget/BudgetRuleAttachable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.budget; 12 | 13 | public interface BudgetRuleAttachable { 14 | 15 | void addBudgetRule(BudgetRule budget); 16 | 17 | void clearAllBudgetRules(); 18 | } 19 | -------------------------------------------------------------------------------- /gradle/release.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "io.github.gradle-nexus.publish-plugin" //https://github.com/gradle-nexus/publish-plugin/ 2 | nexusPublishing { 3 | repositories { 4 | if (System.getenv("SONATYPE_PWD")) { 5 | sonatype { 6 | username = System.getenv("SONATYPE_USER") 7 | password = System.getenv("SONATYPE_PWD") 8 | } 9 | } 10 | } 11 | } 12 | 13 | allprojects { p -> 14 | plugins.withId("java") { 15 | p.apply from: "$rootDir/gradle/java-publication.gradle" 16 | } 17 | } -------------------------------------------------------------------------------- /logback-correlationid/logback-correlationid.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | dependencies { 12 | implementation project(":logback-classic") 13 | 14 | testImplementation 'org.awaitility:awaitility:4.0.2' 15 | testImplementation "net.logstash.logback:logstash-logback-encoder:$logstashVersion" 16 | } 17 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | #Fri Mar 06 17:39:40 PST 2020 13 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip 14 | distributionBase=GRADLE_USER_HOME 15 | distributionPath=wrapper/dists 16 | zipStorePath=wrapper/dists 17 | zipStoreBase=GRADLE_USER_HOME 18 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/NanoTimeSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.classic; 13 | 14 | import com.tersesystems.logback.core.Component; 15 | 16 | public interface NanoTimeSupplier extends Component { 17 | long getNanoTime(); 18 | } 19 | -------------------------------------------------------------------------------- /logback-core/logback-core.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | plugins { 12 | id 'java-library' 13 | } 14 | 15 | dependencies { 16 | api "org.slf4j:slf4j-api:$slf4jVersion" 17 | implementation "ch.qos.logback:logback-core:$logbackVersion" 18 | testImplementation "ch.qos.logback:logback-classic:$logbackVersion" 19 | } -------------------------------------------------------------------------------- /logback-exception-mapping-providers/logback-exception-mapping-providers.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | dependencies { 12 | implementation project(':logback-exception-mapping') 13 | implementation project(':logback-typesafe-config') 14 | 15 | implementation "net.logstash.logback:logstash-logback-encoder:$logstashVersion" 16 | } -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/sift/DiscriminatingValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic.sift; 12 | 13 | import ch.qos.logback.classic.spi.ILoggingEvent; 14 | 15 | public interface DiscriminatingValue { 16 | String getDiscriminatingValue(ILoggingEvent loggingEvent); 17 | } 18 | -------------------------------------------------------------------------------- /logback-censor/src/main/java/com/tersesystems/logback/censor/Censor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.censor; 12 | 13 | import com.tersesystems.logback.core.Component; 14 | 15 | /** Basic censor functionality. */ 16 | public interface Censor extends Component { 17 | CharSequence censorText(CharSequence input); 18 | } 19 | -------------------------------------------------------------------------------- /logback-budget/logback-budget.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | dependencies { 12 | implementation project(':logback-core') 13 | implementation project(':logback-classic') 14 | // https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 15 | implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.9' 16 | } 17 | -------------------------------------------------------------------------------- /logback-honeycomb-appender/logback-honeycomb-appender.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | plugins { 12 | id 'java-library' 13 | } 14 | 15 | dependencies { 16 | api project(":logback-honeycomb-client") 17 | 18 | implementation project(":logback-classic") 19 | implementation "net.logstash.logback:logstash-logback-encoder:$logstashVersion" 20 | } 21 | -------------------------------------------------------------------------------- /logback-censor/logback-censor.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | dependencies { 12 | implementation project(":logback-core") 13 | 14 | implementation "org.slf4j:slf4j-api:$slf4jVersion" 15 | implementation "net.logstash.logback:logstash-logback-encoder:$logstashVersion" 16 | implementation "ch.qos.logback:logback-classic:$logbackVersion" 17 | } 18 | -------------------------------------------------------------------------------- /logback-audio/logback-audio.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | dependencies { 12 | implementation project(':logback-core') 13 | implementation project(':logback-classic') 14 | implementation group: 'com.googlecode.soundlibs', name: 'mp3spi', version: '1.9.5.4' 15 | implementation group: 'com.github.trilarion', name: 'vorbis-support', version: '1.1.0' 16 | } 17 | -------------------------------------------------------------------------------- /logback-exception-mapping/src/main/java/com/tersesystems/logback/exceptionmapping/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.exceptionmapping; 12 | 13 | public final class Constants { 14 | 15 | public static final String REGISTRY_BAG = "EXCEPTION_REGISTRY_BAG"; 16 | 17 | public static final String DEFAULT_MAPPINGS_KEY = "default"; 18 | } 19 | -------------------------------------------------------------------------------- /logback-censor/src/main/java/com/tersesystems/logback/censor/CensorConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.censor; 12 | 13 | public class CensorConstants { 14 | 15 | public static final String CENSOR_BAG = "CENSOR_BAG"; 16 | public static final String REF_ATTRIBUTE = "ref"; 17 | public static final String CENSOR_RULE_NAME = "censor"; 18 | } 19 | -------------------------------------------------------------------------------- /logback-exception-mapping/src/main/java/com/tersesystems/logback/exceptionmapping/ExceptionMapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.exceptionmapping; 12 | 13 | import java.util.List; 14 | import java.util.function.Function; 15 | 16 | public interface ExceptionMapping extends Function> { 17 | String getName(); 18 | } 19 | -------------------------------------------------------------------------------- /logback-correlationid/src/main/java/com/tersesystems/logback/correlationid/CorrelationIdProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.correlationid; 13 | 14 | import com.tersesystems.logback.core.Component; 15 | 16 | /** A correlation id component. */ 17 | public interface CorrelationIdProvider extends Component { 18 | String getCorrelationId(); 19 | } 20 | -------------------------------------------------------------------------------- /logback-compress-encoder/logback-compress-encoder.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | dependencies { 12 | implementation project(':logback-classic') 13 | 14 | implementation group: 'org.apache.commons', name: 'commons-compress', version: '1.18' 15 | implementation "com.github.luben:zstd-jni:$zstdVersion" 16 | 17 | testImplementation "ch.qos.logback:logback-classic:$logbackVersion" 18 | } -------------------------------------------------------------------------------- /logback-uniqueid-appender/src/main/java/com/tersesystems/logback/uniqueid/UniqueIdProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.uniqueid; 13 | 14 | import com.tersesystems.logback.core.Component; 15 | 16 | /** This interface returns a unique id identifying the entity. */ 17 | public interface UniqueIdProvider extends Component { 18 | String uniqueId(); 19 | } 20 | -------------------------------------------------------------------------------- /logback-turbomarker/src/test/java/com/tersesystems/logback/turbomarker/ApplicationContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.turbomarker; 12 | 13 | public class ApplicationContext { 14 | 15 | private final String userId; 16 | 17 | public ApplicationContext(String userId) { 18 | this.userId = userId; 19 | } 20 | 21 | public String currentUserId() { 22 | return userId; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /logback-honeycomb-client/src/main/java/com/tersesystems/logback/honeycomb/client/HoneycombClientService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.honeycomb.client; 13 | 14 | import java.util.function.Function; 15 | 16 | public interface HoneycombClientService { 17 | HoneycombClient newClient( 18 | String apiKey, String dataset, Function, byte[]> encodeFunction); 19 | } 20 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/IContainerLoggingEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.classic; 13 | 14 | import ch.qos.logback.classic.spi.ILoggingEvent; 15 | import com.tersesystems.logback.core.ComponentContainer; 16 | 17 | /** A logging event that is a container of components. */ 18 | public interface IContainerLoggingEvent extends ILoggingEvent, ComponentContainer {} 19 | -------------------------------------------------------------------------------- /logback-bytebuddy/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | %-5relative %-5level %logger{35} - %msg%n 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /logback-correlationid/src/test/resources/logback-correlationid.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | correlationId 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /logback-bytebuddy/src/main/java/com/tersesystems/logback/bytebuddy/impl/LoggerResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.bytebuddy.impl; 12 | 13 | import org.slf4j.Logger; 14 | 15 | /** Finds a logger given some input. */ 16 | public interface LoggerResolver { 17 | /** 18 | * @param origin the class name plus other stuff, provided from bytebuddy advice. 19 | * @return a logger. 20 | */ 21 | Logger resolve(String origin); 22 | } 23 | -------------------------------------------------------------------------------- /logback-uniqueid-appender/src/main/java/com/tersesystems/logback/uniqueid/TsidIdgenerator.java: -------------------------------------------------------------------------------- 1 | package com.tersesystems.logback.uniqueid; 2 | 3 | import com.github.f4b6a3.tsid.TsidFactory; 4 | 5 | /** 6 | * Generates a TSID according to https://github.com/f4b6a3/tsid-creator. 8 | */ 9 | public class TsidIdgenerator implements IdGenerator { 10 | 11 | // "tsidcreator.node" system property should be set, 12 | // but small hope of that happening, so choose a large node count. 13 | private final TsidFactory factory = TsidFactory.newInstance4096(); 14 | 15 | @Override 16 | public String generateId() { 17 | return factory.create().toString(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /logback-turbomarker/src/test/java/com/tersesystems/logback/turbomarker/UserMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.turbomarker; 12 | 13 | public class UserMarker extends ContextAwareTurboMarker { 14 | public UserMarker( 15 | String name, 16 | ApplicationContext applicationContext, 17 | ContextAwareTurboFilterDecider decider) { 18 | super(name, applicationContext, decider); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/TimeSinceEpochConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import ch.qos.logback.classic.pattern.ClassicConverter; 14 | import ch.qos.logback.classic.spi.ILoggingEvent; 15 | 16 | public class TimeSinceEpochConverter extends ClassicConverter { 17 | @Override 18 | public String convert(ILoggingEvent event) { 19 | return Long.toString(event.getTimeStamp()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /logback-core/src/main/java/com/tersesystems/logback/core/ComponentContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.core; 13 | 14 | /** 15 | * A component container. 16 | * 17 | *

Entries are encouraged but not required to extend Component. 18 | */ 19 | public interface ComponentContainer { 20 | void putComponent(Class type, T instance); 21 | 22 | T getComponent(Class type); 23 | 24 | boolean hasComponent(Class type); 25 | } 26 | -------------------------------------------------------------------------------- /logback-honeycomb-okhttp/src/main/resources/META-INF/services/com.tersesystems.logback.honeycomb.client.HoneycombClientService: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | # 13 | # SPDX-License-Identifier: CC0-1.0 14 | # 15 | # Copyright 2018-2020 Will Sargent. 16 | # 17 | # Licensed under the CC0 Public Domain Dedication; 18 | # You may obtain a copy of the License at 19 | # 20 | # http://creativecommons.org/publicdomain/zero/1.0/ 21 | # 22 | 23 | com.tersesystems.logback.honeycomb.okhttp.HoneycombOkHTTPClientService -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/ILoggingEventFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import ch.qos.logback.classic.Level; 14 | import ch.qos.logback.classic.Logger; 15 | import ch.qos.logback.classic.spi.ILoggingEvent; 16 | import org.slf4j.Marker; 17 | 18 | public interface ILoggingEventFactory { 19 | E create(Marker marker, Logger logger, Level level, String msg, Object[] params, Throwable t); 20 | } 21 | -------------------------------------------------------------------------------- /logback-honeycomb-client/src/main/java/com/tersesystems/logback/honeycomb/client/HoneycombHeaders.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.honeycomb.client; 12 | 13 | public class HoneycombHeaders { 14 | public static String teamHeader() { 15 | return "X-Honeycomb-Team"; 16 | } 17 | 18 | public static String eventTimeHeader() { 19 | return "X-Honeycomb-Event-Time"; 20 | } 21 | 22 | public static String sampleRateHeader() { 23 | return "X-Honeycomb-Samplerate"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /logback-censor/src/main/java/com/tersesystems/logback/censor/CensoringPrettyPrintingJsonGeneratorDecorator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.censor; 12 | 13 | import com.fasterxml.jackson.core.JsonGenerator; 14 | 15 | public class CensoringPrettyPrintingJsonGeneratorDecorator extends CensoringJsonGeneratorDecorator 16 | implements CensorAttachable { 17 | @Override 18 | public JsonGenerator decorate(JsonGenerator generator) { 19 | return super.decorate(generator.useDefaultPrettyPrinter()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/URLPlayer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | import ch.qos.logback.core.spi.ContextAwareBase; 14 | import java.net.URL; 15 | 16 | public class URLPlayer extends ContextAwareBase implements Player { 17 | 18 | private URL url; 19 | 20 | public URLPlayer() {} 21 | 22 | public void URLPlayer(URL url) { 23 | this.url = url; 24 | } 25 | 26 | @Override 27 | public void play() { 28 | SimplePlayer.fromURL(url).play(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/SystemPlayer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | import java.awt.*; 14 | 15 | public class SystemPlayer implements Player { 16 | @Override 17 | public void play() { 18 | Toolkit toolkit = Toolkit.getDefaultToolkit(); 19 | 20 | final Runnable exclam = (Runnable) toolkit.getDesktopProperty("win.sound.exclamation"); 21 | if (exclam != null) { 22 | exclam.run(); 23 | } else { 24 | toolkit.beep(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /logback-audio/src/test/resources/logback-with-converter.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | %-5relative %-5level %logger{35} %audio - %msg%n 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /logback-uniqueid-appender/src/main/java/com/tersesystems/logback/uniqueid/KsuidSubsecondIdGenerator.java: -------------------------------------------------------------------------------- 1 | package com.tersesystems.logback.uniqueid; 2 | 3 | import com.github.f4b6a3.ksuid.*; 4 | import java.util.Random; 5 | import java.util.concurrent.ThreadLocalRandom; 6 | 7 | /** 8 | * Creates a subsecond KSUID according to https://github.com/f4b6a3/ksuid-creator. 10 | */ 11 | public class KsuidSubsecondIdGenerator implements IdGenerator { 12 | 13 | private Random random() { 14 | return ThreadLocalRandom.current(); 15 | } 16 | 17 | private final KsuidFactory factory = KsuidFactory.newSubsecondInstance(() -> random().nextLong()); 18 | 19 | @Override 20 | public String generateId() { 21 | return factory.create().toString(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /logback-tracing/logback-tracing.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | dependencies { 12 | //implementation "org.slf4j:slf4j-api:$slf4jVersion" 13 | //implementation project(':logback-uniqueid-appender') 14 | implementation project(':logback-classic') 15 | 16 | implementation "com.google.auto.value:auto-value-annotations:1.6.2" 17 | annotationProcessor "com.google.auto.value:auto-value:1.6.2" 18 | 19 | implementation "net.logstash.logback:logstash-logback-encoder:$logstashVersion" 20 | implementation "ch.qos.logback:logback-classic:$logbackVersion" 21 | } -------------------------------------------------------------------------------- /logback-uniqueid-appender/src/main/java/com/tersesystems/logback/uniqueid/UlidIdGenerator.java: -------------------------------------------------------------------------------- 1 | package com.tersesystems.logback.uniqueid; 2 | 3 | import com.github.f4b6a3.ulid.UlidFactory; 4 | import java.util.Random; 5 | import java.util.concurrent.ThreadLocalRandom; 6 | 7 | /** 8 | * Creates a monotonic ULID using a threadlocal random according to https://github.com/f4b6a3/ulid-creator. 10 | */ 11 | public class UlidIdGenerator implements IdGenerator { 12 | 13 | private Random random() { 14 | return ThreadLocalRandom.current(); 15 | } 16 | 17 | private final UlidFactory factory = UlidFactory.newMonotonicInstance(() -> random().nextLong()); 18 | 19 | @Override 20 | public String generateId() { 21 | return factory.create().toString(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /logback-turbomarker/src/main/java/com/tersesystems/logback/turbomarker/TurboMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.turbomarker; 12 | 13 | import com.tersesystems.logback.classic.TerseBasicMarker; 14 | import com.tersesystems.logback.classic.TurboFilterDecider; 15 | 16 | /** 17 | * This class is a marker that can test to see whether an event should be allowed through a turbo 18 | * filter. 19 | */ 20 | public abstract class TurboMarker extends TerseBasicMarker implements TurboFilterDecider { 21 | public TurboMarker(String name) { 22 | super(name); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /logback-postgresjson-appender/src/test/resources/db/migration/V1__logging_table.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- SPDX-License-Identifier: CC0-1.0 3 | -- 4 | -- Copyright 2018-2019 Will Sargent. 5 | -- 6 | -- Licensed under the CC0 Public Domain Dedication; 7 | -- You may obtain a copy of the License at 8 | -- 9 | -- http://creativecommons.org/publicdomain/zero/1.0/ 10 | -- 11 | 12 | -- timestamp will only give microsecond precision, so we store both timestamp and time since epoch in milliseconds. 13 | -- store the start time in milliseconds. 14 | CREATE TABLE logging_table ( 15 | ID serial NOT NULL PRIMARY KEY, 16 | ts TIMESTAMPTZ(6) NOT NULL, 17 | tse_ms numeric NOT NULL, 18 | start_ms numeric NULL, 19 | level_value int NOT NULL, 20 | level VARCHAR(7) NOT NULL, 21 | evt jsonb NOT NULL 22 | ); 23 | 24 | CREATE INDEX idxgin ON logging_table USING gin (evt); -------------------------------------------------------------------------------- /logback-bytebuddy/src/test/java/com/tersesystems/logback/bytebuddy/ClassCalledByAgent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.bytebuddy; 12 | 13 | /** This class does no logging. */ 14 | public class ClassCalledByAgent { 15 | public void printStatement() { 16 | System.out.println("I am a simple println method with no logging"); 17 | } 18 | 19 | public void printArgument(String arg) { 20 | System.out.println("I am a simple println, printing " + arg); 21 | } 22 | 23 | public void throwException(String arg) { 24 | throw new RuntimeException("I'm a squirrel!"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/NanoTimeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.classic; 13 | 14 | import ch.qos.logback.classic.pattern.ClassicConverter; 15 | import ch.qos.logback.classic.spi.ILoggingEvent; 16 | 17 | /** A relative time converter that returns number of nanoseconds from NanoTime.start. */ 18 | public class NanoTimeConverter extends ClassicConverter { 19 | @Override 20 | public String convert(ILoggingEvent event) { 21 | return NanoTime.fromOptional(getContext(), event).map(st -> Long.toString(st)).orElse(null); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /logback-audio/src/test/resources/logback-with-marker-appender.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | %-5relative %-5level %logger{35} - %msg%n 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /logback-bytebuddy/src/main/java/com/tersesystems/logback/bytebuddy/impl/FixedLoggerResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.bytebuddy.impl; 12 | 13 | import static java.util.Objects.requireNonNull; 14 | 15 | import org.slf4j.Logger; 16 | 17 | /** Always returns the same logger. */ 18 | public class FixedLoggerResolver implements LoggerResolver { 19 | private final Logger logger; 20 | 21 | public FixedLoggerResolver(Logger logger) { 22 | this.logger = requireNonNull(logger); 23 | } 24 | 25 | @Override 26 | public Logger resolve(String origin) { 27 | return logger; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /logback-censor/src/main/java/com/tersesystems/logback/censor/CensorContextAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.censor; 12 | 13 | import ch.qos.logback.core.spi.ContextAware; 14 | import ch.qos.logback.core.spi.LifeCycle; 15 | 16 | public interface CensorContextAware extends Censor, ContextAware, LifeCycle { 17 | 18 | /** Get the name of this appender. The name uniquely identifies the appender. */ 19 | String getName(); 20 | 21 | /** 22 | * Set the name of this appender. The name is used by other components to identify this appender. 23 | */ 24 | void setName(String name); 25 | } 26 | -------------------------------------------------------------------------------- /logback-compress-encoder/src/test/resources/logback-with-zstd-encoder.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | encoded.zst 15 | zstd 16 | 10240 17 | 18 | UTF-8 19 | %-5level %logger{35} - %msg%n 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /logback-jdbc-appender/logback-jdbc-appender.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | plugins { 12 | id 'java-library' 13 | } 14 | 15 | dependencies { 16 | api project(':logback-classic') 17 | 18 | // .200 has the JSON data type 19 | implementation "com.zaxxer:HikariCP:3.4.2" 20 | 21 | testImplementation "com.h2database:h2:1.4.200" 22 | testImplementation project(':logback-typesafe-config') 23 | testImplementation 'org.awaitility:awaitility:4.0.2' 24 | 25 | testImplementation 'org.apiguardian:apiguardian-api:1.1.0' 26 | testImplementation "net.logstash.logback:logstash-logback-encoder:$logstashVersion" 27 | } -------------------------------------------------------------------------------- /logback-postgresjson-appender/logback-postgresjson-appender.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | dependencies { 12 | implementation project(":logback-jdbc-appender") 13 | 14 | implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.6' 15 | 16 | // Need to set up a FlywayBaseTest, the gradle plugin won't run a "testFlywayMigrate" task 17 | // testImplementation "org.flywaydb:flyway-core:6.0.0" 18 | // technically any JSON string is valid input, so we only require logstash-logback-encoder for testing 19 | testImplementation "net.logstash.logback:logstash-logback-encoder:$logstashVersion" 20 | } 21 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/PlayerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | public class PlayerException extends RuntimeException { 14 | public PlayerException() {} 15 | 16 | public PlayerException(String s) { 17 | super(s); 18 | } 19 | 20 | public PlayerException(String s, Throwable throwable) { 21 | super(s, throwable); 22 | } 23 | 24 | public PlayerException(Throwable throwable) { 25 | super(throwable); 26 | } 27 | 28 | public PlayerException(String s, Throwable throwable, boolean b, boolean b1) { 29 | super(s, throwable, b, b1); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /logback-turbomarker/src/main/java/com/tersesystems/logback/turbomarker/ContextAwareTurboFilterDecider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.turbomarker; 12 | 13 | import ch.qos.logback.classic.Level; 14 | import ch.qos.logback.classic.Logger; 15 | import ch.qos.logback.core.spi.FilterReply; 16 | import org.slf4j.Marker; 17 | 18 | public interface ContextAwareTurboFilterDecider { 19 | FilterReply decide( 20 | ContextAwareTurboMarker marker, 21 | C context, 22 | Marker rootMarker, 23 | Logger logger, 24 | Level level, 25 | String format, 26 | Object[] params, 27 | Throwable t); 28 | } 29 | -------------------------------------------------------------------------------- /logback-core/src/test/resources/logback-with-composite-appender.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /logback-tracing/src/main/java/com/tersesystems/logback/tracing/Nullable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.tracing; 12 | 13 | import static java.lang.annotation.ElementType.TYPE_USE; 14 | import static java.lang.annotation.RetentionPolicy.SOURCE; 15 | 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.Target; 18 | 19 | /** 20 | * autovalue wants a Nullable but doesn't tell us from where. 21 | * 22 | *

anything will work, so defining one here. 23 | * 24 | *

https://github.com/google/auto/issues/283#issuecomment-337281043 25 | */ 26 | @Target(TYPE_USE) 27 | @Retention(SOURCE) 28 | @interface Nullable {} 29 | -------------------------------------------------------------------------------- /logback-classic/src/test/java/com/tersesystems/logback/classic/ChangeLogLevelTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import org.junit.Test; 14 | 15 | public class ChangeLogLevelTest { 16 | 17 | @Test 18 | public void testChangeLogLevel() { 19 | // ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory(); 20 | // ChangeLogLevel changeLogLevel = new ChangeLogLevel(); 21 | // Logger logger = loggerFactory.getLogger("example"); 22 | // assertThat(logger.isTraceEnabled()).isFalse(); 23 | // changeLogLevel.changeLogLevel(logger, "TRACE"); 24 | // assertThat(logger.isTraceEnabled()).isTrue(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/StartTimeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import ch.qos.logback.classic.pattern.ClassicConverter; 14 | import ch.qos.logback.classic.spi.ILoggingEvent; 15 | import java.util.Optional; 16 | 17 | /** Returns start time in milliseconds. */ 18 | public class StartTimeConverter extends ClassicConverter { 19 | @Override 20 | public String convert(ILoggingEvent event) { 21 | Optional optStartTime = 22 | StartTime.fromOptional(getContext(), event).map(st -> Long.toString(st.toEpochMilli())); 23 | return optStartTime.orElse(null); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/LoggerDecider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import ch.qos.logback.classic.Logger; 14 | import ch.qos.logback.core.spi.FilterReply; 15 | import java.util.function.Function; 16 | import org.slf4j.Marker; 17 | 18 | @FunctionalInterface 19 | public interface LoggerDecider extends Function, TurboFilterDecider { 20 | default FilterReply decide( 21 | Marker marker, 22 | Logger logger, 23 | ch.qos.logback.classic.Level level, 24 | String format, 25 | Object[] params, 26 | Throwable t) { 27 | return apply(logger); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /logback-turbomarker/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /logback-uniqueid-appender/src/main/java/com/tersesystems/logback/uniqueid/UniqueIdConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.uniqueid; 12 | 13 | import ch.qos.logback.classic.spi.ILoggingEvent; 14 | import ch.qos.logback.core.pattern.DynamicConverter; 15 | import com.tersesystems.logback.core.ComponentContainer; 16 | 17 | public class UniqueIdConverter extends DynamicConverter { 18 | @Override 19 | public String convert(ILoggingEvent event) { 20 | if (event instanceof ComponentContainer) { 21 | return ((ComponentContainer) event).getComponent(UniqueIdProvider.class).uniqueId(); 22 | } else { 23 | return null; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /logback-bytebuddy/src/test/java/com/tersesystems/logback/bytebuddy/PreloadedInstrumentationExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.bytebuddy; 12 | 13 | /** 14 | * Borrowed from securityfixer, showing tracing when you set the security manager. 15 | * 16 | *

Will not work on native methods, i.e. `System.currentTimeMillis`. 17 | * 18 | *

Move this into the main source path and redeploy if you want to test (I can't figure out how 19 | * to do agent stuff in Gradle) 20 | */ 21 | public class PreloadedInstrumentationExample { 22 | public static void main(String[] args) throws Exception { 23 | Thread thread = Thread.currentThread(); 24 | thread.run(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/FormatParamsDecider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import ch.qos.logback.classic.Level; 14 | import ch.qos.logback.classic.Logger; 15 | import ch.qos.logback.core.spi.FilterReply; 16 | import java.util.function.BiFunction; 17 | import org.slf4j.Marker; 18 | 19 | @FunctionalInterface 20 | public interface FormatParamsDecider 21 | extends BiFunction, TurboFilterDecider { 22 | @Override 23 | default FilterReply decide( 24 | Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) { 25 | return apply(format, params); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /logback-honeycomb-okhttp/logback-honeycomb-okhttp.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | plugins { 12 | id 'java-library' 13 | } 14 | 15 | dependencies { 16 | api project(":logback-honeycomb-client") 17 | 18 | implementation "ch.qos.logback:logback-classic:$logbackVersion" 19 | 20 | // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind 21 | implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.9' 22 | 23 | implementation("com.squareup.okhttp3:okhttp:4.1.0") 24 | 25 | implementation group: 'com.google.auto.service', name: 'auto-service', version: '1.0-rc6' 26 | annotationProcessor "com.google.auto.service:auto-service:1.0-rc6" 27 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-License-Identifier: CC0-1.0 3 | # 4 | # Copyright 2018-2020 Will Sargent. 5 | # 6 | # Licensed under the CC0 Public Domain Dedication; 7 | # You may obtain a copy of the License at 8 | # 9 | # http://creativecommons.org/publicdomain/zero/1.0/ 10 | # 11 | 12 | group = com.tersesystems.logback 13 | 14 | org.gradle.caching=true 15 | 16 | # Set to true to attach a debugger 17 | org.gradle.debug=false 18 | 19 | # Set the memory size of the daemon to be higher because animalsniffer needs it. 20 | #org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 21 | 22 | bytebuddyVersion = 1.11.5 23 | junitVersion = 4.12 24 | junitJupiterVersion = 5.0.1 25 | junitVintageVersion = 4.12.1 26 | junitPlatformVersion = 1.0.1 27 | slf4jVersion = 1.7.36 28 | logstashVersion = 6.3 29 | logbackVersion = 1.2.10 30 | configVersion = 1.4.0 31 | zstdVersion = 1.5.2-2 32 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/MarkerLoggerDecider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import ch.qos.logback.classic.Logger; 14 | import ch.qos.logback.core.spi.FilterReply; 15 | import java.util.function.BiFunction; 16 | import org.slf4j.Marker; 17 | 18 | @FunctionalInterface 19 | public interface MarkerLoggerDecider 20 | extends BiFunction, TurboFilterDecider { 21 | default FilterReply decide( 22 | Marker marker, 23 | Logger logger, 24 | ch.qos.logback.classic.Level level, 25 | String format, 26 | Object[] params, 27 | Throwable t) { 28 | return apply(marker, logger); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /logback-exception-mapping-providers/src/test/java/com/tersesystems/logback/exceptionmapping/json/MySpecialException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.exceptionmapping.json; 12 | 13 | import java.time.Instant; 14 | 15 | public class MySpecialException extends Exception { 16 | 17 | private final Instant timestamp; 18 | 19 | public MySpecialException(String message, Instant timestamp) { 20 | super(message); 21 | this.timestamp = timestamp; 22 | } 23 | 24 | public MySpecialException(String message, Instant timestamp, Throwable cause) { 25 | super(message, cause); 26 | this.timestamp = timestamp; 27 | } 28 | 29 | public Instant getTimestamp() { 30 | return timestamp; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /logback-uniqueid-appender/logback-uniqueid-appender.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | dependencies { 12 | implementation project(':logback-classic') 13 | 14 | // https://github.com/f4b6a3/ulid-creator 15 | implementation 'com.github.f4b6a3:ulid-creator:5.1.0' 16 | 17 | // https://github.com/f4b6a3/tsid-creator 18 | implementation 'com.github.f4b6a3:tsid-creator:5.2.0' 19 | 20 | // https://github.com/f4b6a3/uuid-creator 21 | implementation 'com.github.f4b6a3:uuid-creator:5.2.0' 22 | 23 | // https://github.com/f4b6a3/ksuid-creator 24 | implementation 'com.github.f4b6a3:ksuid-creator:4.1.0' 25 | 26 | // https://github.com/mguenther/idem 27 | implementation 'net.mguenther.idem:idem-core:0.1.0' 28 | } 29 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/ContainerEventAppender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.classic; 13 | 14 | import ch.qos.logback.classic.spi.ILoggingEvent; 15 | import com.tersesystems.logback.core.DecoratingAppender; 16 | 17 | /** 18 | * This appender decorates the out of the box logging event with a component system, which allows 19 | * extra attributes to be added to the event. 20 | */ 21 | public class ContainerEventAppender 22 | extends DecoratingAppender { 23 | @Override 24 | protected IContainerLoggingEvent decorateEvent(ILoggingEvent eventObject) { 25 | return new ContainerProxyLoggingEvent(eventObject); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /logback-core/src/main/java/com/tersesystems/logback/core/EnabledFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.core; 12 | 13 | import ch.qos.logback.core.filter.Filter; 14 | import ch.qos.logback.core.spi.FilterReply; 15 | 16 | /** Used to enable and disable appenders. */ 17 | public class EnabledFilter extends Filter { 18 | 19 | private boolean enabled; 20 | 21 | @Override 22 | public FilterReply decide(E event) { 23 | if (isStarted() && isEnabled()) { 24 | return FilterReply.NEUTRAL; 25 | } else { 26 | return FilterReply.DENY; 27 | } 28 | } 29 | 30 | public boolean isEnabled() { 31 | return enabled; 32 | } 33 | 34 | public void setEnabled(boolean enabled) { 35 | this.enabled = enabled; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /logback-exception-mapping/src/test/java/com/tersesystems/logback/exceptionmapping/MyCustomException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.exceptionmapping; 12 | 13 | public class MyCustomException extends RuntimeException { 14 | private final String one; 15 | private final String two; 16 | private final String three; 17 | 18 | public MyCustomException(String message, String one, String two, String three, Throwable cause) { 19 | super(message, cause); 20 | this.one = one; 21 | this.two = two; 22 | this.three = three; 23 | } 24 | 25 | public String getOne() { 26 | return one; 27 | } 28 | 29 | public String getTwo() { 30 | return two; 31 | } 32 | 33 | public String getThree() { 34 | return three; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /logback-jdbc-appender/src/test/resources/logback-reference.conf: -------------------------------------------------------------------------------- 1 | levels { 2 | ROOT = INFO 3 | } 4 | 5 | local { 6 | jdbc { 7 | url = "jdbc:h2:mem:terse-logback" 8 | driver = "org.h2.Driver" 9 | username = "sa" 10 | password = "" 11 | insertStatement = "insert into events(ts, relative_ns, start_ms, level_value, level, evt) values(?, ?, ?, ?, ?, ?)" 12 | createStatements = """ 13 | CREATE TABLE IF NOT EXISTS events ( 14 | ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, 15 | ts TIMESTAMP(9) WITH TIME ZONE NOT NULL, 16 | relative_ns numeric NULL, 17 | start_ms numeric NULL, 18 | level_value int NOT NULL, 19 | level VARCHAR(7) NOT NULL, 20 | evt JSON NOT NULL 21 | ); 22 | """ 23 | reaperStatement = "delete from events where ts < ?" 24 | reaperSchedule = PT30 25 | } 26 | } 27 | 28 | # Defines properties (Strings) to be set in context scope (loggerContext.putProperty) 29 | # See https://logback.qos.ch/manual/configuration.html#scopes 30 | context { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/LoggingEventFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import static ch.qos.logback.classic.Logger.FQCN; 14 | 15 | import ch.qos.logback.classic.Level; 16 | import ch.qos.logback.classic.Logger; 17 | import ch.qos.logback.classic.spi.ILoggingEvent; 18 | import ch.qos.logback.classic.spi.LoggingEvent; 19 | import org.slf4j.Marker; 20 | 21 | public class LoggingEventFactory implements ILoggingEventFactory { 22 | public ILoggingEvent create( 23 | Marker marker, Logger logger, Level level, String msg, Object[] params, Throwable t) { 24 | LoggingEvent le = new LoggingEvent(FQCN, logger, level, msg, t, params); 25 | le.setMarker(marker); 26 | return le; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /logback-honeycomb-client/src/main/java/com/tersesystems/logback/honeycomb/client/HoneycombRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.honeycomb.client; 12 | 13 | import java.time.Instant; 14 | 15 | public class HoneycombRequest { 16 | 17 | private final Integer sampleRate; 18 | private final E event; 19 | private final Instant timestamp; 20 | 21 | public HoneycombRequest(Integer sampleRate, Instant timestamp, E event) { 22 | this.sampleRate = sampleRate; 23 | this.timestamp = timestamp; 24 | this.event = event; 25 | } 26 | 27 | public E getEvent() { 28 | return event; 29 | } 30 | 31 | public Integer getSampleRate() { 32 | return sampleRate; 33 | } 34 | 35 | public Instant getTimestamp() { 36 | return timestamp; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /logback-budget/src/test/java/com.tersesystems.logback.budget/BudgetTurboFilterTest.java: -------------------------------------------------------------------------------- 1 | package com.tersesystems.logback.budget; 2 | 3 | import ch.qos.logback.classic.Logger; 4 | import ch.qos.logback.classic.LoggerContext; 5 | import ch.qos.logback.classic.joran.JoranConfigurator; 6 | import ch.qos.logback.core.joran.spi.JoranException; 7 | import java.net.URL; 8 | import org.junit.Test; 9 | 10 | public class BudgetTurboFilterTest { 11 | 12 | @Test 13 | public void testBudget() throws JoranException, InterruptedException { 14 | LoggerContext context = new LoggerContext(); 15 | 16 | URL resource = getClass().getResource("/logback-turbofilter.xml"); 17 | JoranConfigurator configurator = new JoranConfigurator(); 18 | configurator.setContext(context); 19 | configurator.doConfigure(resource); 20 | 21 | Logger logger = context.getLogger("some.random.Logger"); 22 | 23 | for (int i = 0; i < 10; i++) { 24 | logger.info("Hello world"); 25 | } 26 | Thread.sleep(1000); 27 | 28 | logger.info("Hello world"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/NanoTimeMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.classic; 13 | 14 | public class NanoTimeMarker extends TerseBasicMarker implements NanoTimeSupplier { 15 | private static final String NANOTIME_MARKER_NAME = "TS_NANOTIME_MARKER"; 16 | private final long nanoTime; 17 | 18 | public NanoTimeMarker() { 19 | super(NANOTIME_MARKER_NAME); 20 | this.nanoTime = System.nanoTime() - NanoTime.start; 21 | } 22 | 23 | public long getNanoTime() { 24 | return nanoTime; 25 | } 26 | 27 | public static NanoTimeMarker create() { 28 | return new NanoTimeMarker(); 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "NanoTimeMarker{" + "nanoTime=" + nanoTime + '}'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /logback-classic/src/test/resources/logback-tapfilter.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | %-5relative %-5level %logger{35} - %msg%n 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /logback-turbomarker/src/main/java/com/tersesystems/logback/turbomarker/ContextDecider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.turbomarker; 12 | 13 | import ch.qos.logback.classic.Level; 14 | import ch.qos.logback.classic.Logger; 15 | import ch.qos.logback.core.spi.FilterReply; 16 | import java.util.function.Function; 17 | import org.slf4j.Marker; 18 | 19 | public interface ContextDecider 20 | extends Function, ContextAwareTurboFilterDecider { 21 | @Override 22 | default FilterReply decide( 23 | ContextAwareTurboMarker marker, 24 | C context, 25 | Marker rootMarker, 26 | Logger logger, 27 | Level level, 28 | String format, 29 | Object[] params, 30 | Throwable t) { 31 | return apply(context); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/StartTimeMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import java.time.Instant; 14 | import java.util.Objects; 15 | 16 | public class StartTimeMarker extends TerseBasicMarker implements StartTimeSupplier { 17 | private static final String TS_STARTTIME_MARKER = "TS_STARTTIME_MARKER"; 18 | private final Instant startTime; 19 | 20 | public StartTimeMarker(Instant start) { 21 | super(TS_STARTTIME_MARKER); 22 | this.startTime = Objects.requireNonNull(start); 23 | } 24 | 25 | @Override 26 | public Instant getStartTime() { 27 | return startTime; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "StartTimeMarker{" + "startTime=" + startTime + '}'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /logback-exception-mapping/src/main/java/com/tersesystems/logback/exceptionmapping/FunctionExceptionMapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.exceptionmapping; 12 | 13 | import java.util.List; 14 | import java.util.function.Function; 15 | 16 | public class FunctionExceptionMapping implements ExceptionMapping { 17 | private final Function> function; 18 | private final String name; 19 | 20 | public FunctionExceptionMapping(String name, Function> f) { 21 | this.name = name; 22 | this.function = f; 23 | } 24 | 25 | @Override 26 | public List apply(Throwable e) { 27 | return function.apply(e); 28 | } 29 | 30 | @Override 31 | public String getName() { 32 | return name; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /logback-typesafe-config/src/test/resources/typesafeconfig/config-with-local.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | [%-5level] %logger{15} - %msg%n%xException{10} 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /logback-typesafe-config/src/test/resources/typesafeconfig/config-with-default.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | [%-5level] %logger{15} - %msg%n%xException{10} 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /logback-bytebuddy/src/test/java/com/tersesystems/logback/bytebuddy/AdviceConfigTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.bytebuddy; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import com.typesafe.config.Config; 16 | import org.junit.jupiter.api.Test; 17 | 18 | public class AdviceConfigTest { 19 | 20 | @Test 21 | public void testConfig() throws Exception { 22 | ClassLoader classLoader = ClassLoader.getSystemClassLoader(); 23 | Config config = LoggingInstrumentationAdvice.generateConfig(classLoader, false); 24 | AdviceConfig adviceConfig = 25 | LoggingInstrumentationAdvice.generateAdviceConfig(classLoader, config, false); 26 | assertThat(adviceConfig.classNames()) 27 | .contains("com.tersesystems.logback.bytebuddy.ClassCalledByAgent"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /logback-uniqueid-appender/src/main/java/com/tersesystems/logback/uniqueid/FlakeIdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.uniqueid; 12 | 13 | import net.mguenther.idem.flake.Flake128S; 14 | import net.mguenther.idem.provider.LinearTimeProvider; 15 | import net.mguenther.idem.provider.MacAddressWorkerIdProvider; 16 | 17 | /** 18 | * This class generates a 128 bit flake id with a macaddress workerid according to https://github.com/mguenther/idem. 20 | */ 21 | public class FlakeIdGenerator implements IdGenerator { 22 | 23 | private static final Flake128S flake64 = 24 | new Flake128S(new LinearTimeProvider(), new MacAddressWorkerIdProvider()); 25 | 26 | @Override 27 | public String generateId() { 28 | return flake64.nextId(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /logback-typesafe-config/src/test/resources/typesafeconfig/config-with-context.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | [%-5level] %logger{15} - %msg%n%xException{10} 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /logback-budget/src/test/resources/logback-turbofilter.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | INFO 16 | 5 17 | 1 18 | second 19 | 20 | DENY 21 | NEUTRAL 22 | 23 | 24 | 25 | 26 | %-5relative %-5level %logger{35} - %msg%n 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/TurboFilterDecider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import ch.qos.logback.classic.Level; 14 | import ch.qos.logback.classic.Logger; 15 | import ch.qos.logback.core.spi.FilterReply; 16 | import org.slf4j.Marker; 17 | 18 | /** 19 | * An interface that decides what sort of filter reply there is. 20 | * 21 | *

Logback doesn't provide an interface for this out of the box for all turbofilters, so we have 22 | * to add one in by hand when we want decisions without the whole turbo filter. 23 | * 24 | *

This comes in handy for turbomarkers and tap filters. 25 | */ 26 | public interface TurboFilterDecider { 27 | FilterReply decide( 28 | Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t); 29 | } 30 | -------------------------------------------------------------------------------- /logback-turbomarker/src/main/java/com/tersesystems/logback/turbomarker/LoggerContextDecider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.turbomarker; 12 | 13 | import ch.qos.logback.classic.Level; 14 | import ch.qos.logback.classic.Logger; 15 | import ch.qos.logback.core.spi.FilterReply; 16 | import java.util.function.BiFunction; 17 | import org.slf4j.Marker; 18 | 19 | @FunctionalInterface 20 | public interface LoggerContextDecider 21 | extends BiFunction, ContextAwareTurboFilterDecider { 22 | default FilterReply decide( 23 | ContextAwareTurboMarker marker, 24 | C context, 25 | Marker rootMarker, 26 | Logger logger, 27 | Level level, 28 | String format, 29 | Object[] params, 30 | Throwable t) { 31 | return apply(logger, context); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /logback-core/src/test/java/com/tersesystems/logback/core/TestAppender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.core; 12 | 13 | import ch.qos.logback.classic.spi.ILoggingEvent; 14 | import ch.qos.logback.core.AppenderBase; 15 | import ch.qos.logback.core.encoder.Encoder; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | public class TestAppender extends AppenderBase { 20 | 21 | protected Encoder encoder; 22 | 23 | public static List events = new ArrayList<>(); 24 | 25 | public Encoder getEncoder() { 26 | return encoder; 27 | } 28 | 29 | public void setEncoder(Encoder encoder) { 30 | this.encoder = encoder; 31 | } 32 | 33 | @Override 34 | protected void append(ILoggingEvent e) { 35 | events.add(e); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /logback-censor/src/test/java/com/tersesystems/logback/censor/TestAppender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.censor; 12 | 13 | import ch.qos.logback.classic.spi.ILoggingEvent; 14 | import ch.qos.logback.core.AppenderBase; 15 | import ch.qos.logback.core.encoder.Encoder; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | public class TestAppender extends AppenderBase { 20 | 21 | protected Encoder encoder; 22 | 23 | public static List events = new ArrayList<>(); 24 | 25 | public Encoder getEncoder() { 26 | return encoder; 27 | } 28 | 29 | public void setEncoder(Encoder encoder) { 30 | this.encoder = encoder; 31 | } 32 | 33 | @Override 34 | protected void append(ILoggingEvent e) { 35 | events.add(e); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /logback-classic/src/test/java/com/tersesystems/logback/classic/CorrelationIdMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.classic; 13 | 14 | import org.slf4j.Marker; 15 | 16 | /** A very simple correlation id marker. */ 17 | public interface CorrelationIdMarker extends Marker { 18 | String getCorrelationId(); 19 | 20 | static CorrelationIdMarker create(String value) { 21 | return new CorrelationIdBasicMarker(value); 22 | } 23 | } 24 | 25 | /** Implementation of correlation id. */ 26 | class CorrelationIdBasicMarker extends TerseBasicMarker implements CorrelationIdMarker { 27 | private final String value; 28 | 29 | public CorrelationIdBasicMarker(String value) { 30 | super("TS_CORRELATION_ID"); 31 | this.value = value; 32 | } 33 | 34 | public String getCorrelationId() { 35 | return value; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /logback-postgresjson-appender/src/test/java/com/tersesystems/logback/postgresjson/PostgresJsonAppenderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.postgresjson; 12 | 13 | import ch.qos.logback.classic.Logger; 14 | import ch.qos.logback.core.joran.spi.JoranException; 15 | import com.tersesystems.logback.classic.Utils; 16 | import org.junit.jupiter.api.Disabled; 17 | import org.junit.jupiter.api.Test; 18 | 19 | public class PostgresJsonAppenderTest { 20 | 21 | @Disabled 22 | @Test 23 | public void testJson() throws JoranException, InterruptedException { 24 | 25 | Utils utils = Utils.create("/logback-postgres-json.xml"); 26 | Logger logger1 = utils.getLogger("com.example.Test"); 27 | logger1.info("THIS IS A TEST"); 28 | 29 | Thread.sleep(1000); 30 | 31 | utils.getStatusList().forEach(System.out::println); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /logback-uniqueid-appender/src/main/java/com/tersesystems/logback/uniqueid/RandomUUIDIdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.uniqueid; 12 | 13 | import com.github.f4b6a3.uuid.factory.rfc4122.RandomBasedFactory; 14 | import java.util.Random; 15 | import java.util.concurrent.ThreadLocalRandom; 16 | 17 | /** 18 | * Generates a Random UUIDv4 using a ThreadLocalRandom from https://github.com/f4b6a3/uuid-creator 20 | */ 21 | public class RandomUUIDIdGenerator implements IdGenerator { 22 | private Random random() { 23 | return ThreadLocalRandom.current(); 24 | } 25 | 26 | private final RandomBasedFactory factory = new RandomBasedFactory(() -> random().nextLong()); 27 | 28 | @Override 29 | public String generateId() { 30 | return factory.create().toString(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/AudioAppender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | import ch.qos.logback.classic.spi.ILoggingEvent; 14 | import ch.qos.logback.core.AppenderBase; 15 | 16 | public class AudioAppender extends AppenderBase implements PlayerAttachable { 17 | 18 | private Player player; 19 | 20 | @Override 21 | protected void append(ILoggingEvent eventObject) { 22 | player.play(); 23 | } 24 | 25 | @Override 26 | public void addPlayer(Player player) { 27 | this.player = player; 28 | } 29 | 30 | @Override 31 | public void clearAllPlayers() { 32 | this.player = null; 33 | } 34 | 35 | @Override 36 | public void start() { 37 | if (player == null) { 38 | addError("No player found!"); 39 | } else { 40 | super.start(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /logback-correlationid/src/test/resources/logback-correlationid-tapfilter.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | correlationId 21 | 22 | 23 | 24 | 25 | 26 | %-5relative %-5level %logger{35} - %msg%n 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /logback-honeycomb-client/src/main/java/com/tersesystems/logback/honeycomb/client/HoneycombClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.honeycomb.client; 12 | 13 | import java.util.List; 14 | import java.util.concurrent.CompletionStage; 15 | import java.util.function.Function; 16 | 17 | public interface HoneycombClient { 18 | 19 | CompletionStage post(HoneycombRequest request); 20 | 21 | CompletionStage post( 22 | HoneycombRequest request, Function, byte[]> encodeFunction); 23 | 24 | CompletionStage> postBatch(Iterable> requests); 25 | 26 | CompletionStage> postBatch( 27 | Iterable> requests, Function, byte[]> encodeFunction); 28 | 29 | CompletionStage close(); 30 | } 31 | -------------------------------------------------------------------------------- /logback-turbomarker/src/main/java/com/tersesystems/logback/turbomarker/MarkerContextDecider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.turbomarker; 12 | 13 | import ch.qos.logback.classic.Level; 14 | import ch.qos.logback.classic.Logger; 15 | import ch.qos.logback.core.spi.FilterReply; 16 | import java.util.function.BiFunction; 17 | import org.slf4j.Marker; 18 | 19 | @FunctionalInterface 20 | public interface MarkerContextDecider 21 | extends BiFunction, C, FilterReply>, 22 | ContextAwareTurboFilterDecider { 23 | @Override 24 | default FilterReply decide( 25 | ContextAwareTurboMarker marker, 26 | C context, 27 | Marker rootMarker, 28 | Logger logger, 29 | Level level, 30 | String format, 31 | Object[] params, 32 | Throwable t) { 33 | return apply(marker, context); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/sift/DiscriminatingMarkerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic.sift; 12 | 13 | import ch.qos.logback.classic.spi.ILoggingEvent; 14 | import java.util.function.Function; 15 | 16 | public class DiscriminatingMarkerFactory { 17 | 18 | private final Function discriminatingFunction; 19 | 20 | public DiscriminatingMarkerFactory(Function discriminatingFunction) { 21 | this.discriminatingFunction = discriminatingFunction; 22 | } 23 | 24 | public static DiscriminatingMarkerFactory create( 25 | Function discriminatingFunction) { 26 | return new DiscriminatingMarkerFactory(discriminatingFunction); 27 | } 28 | 29 | public DiscriminatingMarker createMarker() { 30 | return new DiscriminatingMarker(discriminatingFunction); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /logback-correlationid/src/main/java/com/tersesystems/logback/correlationid/CorrelationIdMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.correlationid; 13 | 14 | import com.tersesystems.logback.classic.TerseBasicMarker; 15 | import org.slf4j.Marker; 16 | 17 | /** A very simple correlation id marker. */ 18 | public interface CorrelationIdMarker extends Marker, CorrelationIdProvider { 19 | static CorrelationIdMarker create(String value) { 20 | return new CorrelationIdBasicMarker(value); 21 | } 22 | } 23 | 24 | /** Implementation of correlation id. */ 25 | class CorrelationIdBasicMarker extends TerseBasicMarker implements CorrelationIdMarker { 26 | private final String value; 27 | 28 | public CorrelationIdBasicMarker(String value) { 29 | super("TS_CORRELATION_ID"); 30 | this.value = value; 31 | } 32 | 33 | public String getCorrelationId() { 34 | return value; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /logback-honeycomb-okhttp/src/main/java/com/tersesystems/logback/honeycomb/okhttp/HoneycombOkHTTPClientService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.honeycomb.okhttp; 13 | 14 | import com.fasterxml.jackson.core.JsonFactory; 15 | import com.tersesystems.logback.honeycomb.client.HoneycombClient; 16 | import com.tersesystems.logback.honeycomb.client.HoneycombClientService; 17 | import com.tersesystems.logback.honeycomb.client.HoneycombRequest; 18 | import java.util.function.Function; 19 | import okhttp3.OkHttpClient; 20 | 21 | public class HoneycombOkHTTPClientService implements HoneycombClientService { 22 | @Override 23 | public HoneycombClient newClient( 24 | String apiKey, String dataset, Function, byte[]> encodeFunction) { 25 | return new HoneycombOkHTTPClient( 26 | new OkHttpClient(), new JsonFactory(), apiKey, dataset, encodeFunction); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /logback-exception-mapping/src/test/java/com/tersesystems/logback/exceptionmapping/Thrower.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.exceptionmapping; 12 | 13 | import java.sql.BatchUpdateException; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | 17 | public class Thrower { 18 | private static final Logger logger = LoggerFactory.getLogger(Thrower.class); 19 | 20 | public static void main(String[] progArgs) { 21 | try { 22 | doSomethingExceptional(); 23 | } catch (RuntimeException e) { 24 | logger.error("domain specific message", e); 25 | } 26 | } 27 | 28 | static void doSomethingExceptional() { 29 | Throwable cause = new BatchUpdateException(); 30 | throw new MyCustomException( 31 | "This is my message", 32 | "one is one", 33 | "two is more than one", 34 | "three is more than two and one", 35 | cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /logback-turbomarker/src/test/java/com/tersesystems/logback/turbomarker/UserMarkerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.turbomarker; 12 | 13 | import ch.qos.logback.core.spi.FilterReply; 14 | import java.util.Set; 15 | import java.util.concurrent.ConcurrentSkipListSet; 16 | 17 | public class UserMarkerFactory { 18 | 19 | private final Set userIdSet = new ConcurrentSkipListSet<>(); 20 | 21 | private final ContextDecider decider = 22 | context -> 23 | userIdSet.contains(context.currentUserId()) ? FilterReply.ACCEPT : FilterReply.NEUTRAL; 24 | 25 | public void addUserId(String userId) { 26 | userIdSet.add(userId); 27 | } 28 | 29 | public void clear() { 30 | userIdSet.clear(); 31 | } 32 | 33 | public UserMarker create(ApplicationContext applicationContext) { 34 | return new UserMarker("userMarker", applicationContext, decider); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /logback-bytebuddy/src/main/java/com/tersesystems/logback/bytebuddy/impl/DeclaringTypeLoggerResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.bytebuddy.impl; 12 | 13 | import java.util.Objects; 14 | import java.util.function.Supplier; 15 | import org.slf4j.ILoggerFactory; 16 | import org.slf4j.Logger; 17 | 18 | /** Returns the logger with the class that was instrumented. */ 19 | public class DeclaringTypeLoggerResolver implements LoggerResolver { 20 | 21 | private final Supplier loggerFactory; 22 | 23 | public DeclaringTypeLoggerResolver(Supplier loggerFactory) { 24 | this.loggerFactory = Objects.requireNonNull(loggerFactory); 25 | } 26 | 27 | @Override 28 | public Logger resolve(String origin) { 29 | int firstPipe = origin.indexOf('|'); 30 | String declaringType = origin.substring(0, firstPipe); 31 | return loggerFactory.get().getLogger(declaringType); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /logback-turbomarker/logback-turbomarker.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | dependencies { 12 | implementation project(':logback-classic') 13 | implementation "ch.qos.logback:logback-classic:$logbackVersion" 14 | 15 | // https://mvnrepository.com/artifact/org.mockito/mockito-core 16 | testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.0.0' 17 | testImplementation "com.launchdarkly:launchdarkly-java-server-sdk:4.6.6" 18 | testImplementation "net.logstash.logback:logstash-logback-encoder:$logstashVersion" 19 | testImplementation "com.typesafe:config:$configVersion" 20 | //testImplementation "com.fasterxml.jackson.module:jackson-datatype-jdk8" 21 | //testImplementation "com.fasterxml.jackson.module:jackson-datatype-jsr310" 22 | testImplementation 'org.apiguardian:apiguardian-api:1.1.0' 23 | testImplementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.9' 24 | 25 | } 26 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/sift/DiscriminatingMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic.sift; 12 | 13 | import ch.qos.logback.classic.spi.ILoggingEvent; 14 | import com.tersesystems.logback.classic.TerseBasicMarker; 15 | import java.util.function.Function; 16 | 17 | public class DiscriminatingMarker extends TerseBasicMarker implements DiscriminatingValue { 18 | 19 | private static final String TS_DISCRIMINATING_MARKER = "TS_DESCRIMINATING_MARKER"; 20 | private final Function discriminatingFunction; 21 | 22 | public DiscriminatingMarker(Function discriminatingFunction) { 23 | super(TS_DISCRIMINATING_MARKER); 24 | this.discriminatingFunction = discriminatingFunction; 25 | } 26 | 27 | @Override 28 | public String getDiscriminatingValue(ILoggingEvent loggingEvent) { 29 | return discriminatingFunction.apply(loggingEvent); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/functional/RootLoggerSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic.functional; 12 | 13 | import ch.qos.logback.classic.Logger; 14 | import ch.qos.logback.classic.LoggerContext; 15 | import com.tersesystems.logback.classic.Utils; 16 | import java.util.function.Supplier; 17 | 18 | public class RootLoggerSupplier implements Supplier { 19 | 20 | private final LoggerContext loggerContext; 21 | 22 | public RootLoggerSupplier(LoggerContext loggerContext) { 23 | this.loggerContext = loggerContext; 24 | } 25 | 26 | public Logger get() { 27 | return loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); 28 | } 29 | 30 | public static RootLoggerSupplier create(LoggerContext loggerContext) { 31 | return new RootLoggerSupplier(loggerContext); 32 | } 33 | 34 | public static RootLoggerSupplier create() { 35 | return create(Utils.defaultContext()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /logback-budget/src/test/resources/logback-budget.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | INFO 18 | 5 19 | 1 20 | second 21 | 22 | 23 | DENY 24 | NEUTRAL 25 | 26 | 27 | 28 | %-5relative %-5level %logger{35} - %msg%n 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /logback-typesafe-config/src/main/java/com/tersesystems/logback/typesafeconfig/ConfigConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.typesafeconfig; 12 | 13 | /** Constants having to do with typesafe config. */ 14 | public final class ConfigConstants { 15 | 16 | public static final String TYPESAFE_CONFIG_CTX_KEY = "typesafeConfig"; 17 | 18 | public static final String LEVELS_KEY = "levels"; 19 | 20 | public static final String LOGBACK = "logback"; 21 | 22 | public static final String LOGBACK_TEST = "logback-test"; 23 | 24 | public static final String LOGBACK_REFERENCE_CONF = "logback-reference.conf"; 25 | 26 | public static final String CONFIG_FILE_PROPERTY = "terse.logback.configurationFile"; 27 | 28 | public static final String CONTEXT_SCOPE = "context"; 29 | 30 | public static final String LOCAL_SCOPE = "local"; 31 | 32 | public static final String PATH_ATTRIBUTE = "path"; 33 | 34 | public static final String DEBUG_ATTRIBUTE = "debug"; 35 | } 36 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/encoder/PatternLayoutEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.classic.encoder; 13 | 14 | import ch.qos.logback.classic.PatternLayout; 15 | import ch.qos.logback.classic.spi.ILoggingEvent; 16 | import com.tersesystems.logback.core.pattern.PatternLayoutEncoderBase; 17 | 18 | /** 19 | * Create a pattern layout encoder that doesn't require that the parent is an appender. 20 | * 21 | *

This allows for encoders that can take encoders and so on. 22 | */ 23 | public class PatternLayoutEncoder extends PatternLayoutEncoderBase { 24 | 25 | @Override 26 | public void start() { 27 | PatternLayout patternLayout = new PatternLayout(); 28 | patternLayout.setContext(context); 29 | patternLayout.setPattern(getPattern()); 30 | patternLayout.setOutputPatternAsHeader(outputPatternAsHeader); 31 | patternLayout.start(); 32 | this.layout = patternLayout; 33 | super.start(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /logback-correlationid/src/main/java/com/tersesystems/logback/correlationid/CorrelationIdDecider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.correlationid; 13 | 14 | import ch.qos.logback.classic.Level; 15 | import ch.qos.logback.classic.Logger; 16 | import ch.qos.logback.core.spi.FilterReply; 17 | import com.tersesystems.logback.classic.TurboFilterDecider; 18 | import java.util.Optional; 19 | import org.slf4j.Marker; 20 | 21 | public class CorrelationIdDecider implements TurboFilterDecider { 22 | protected final CorrelationIdUtils utils; 23 | 24 | public CorrelationIdDecider(CorrelationIdUtils utils) { 25 | this.utils = utils; 26 | } 27 | 28 | @Override 29 | public FilterReply decide( 30 | Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) { 31 | Optional maybeCorrelationId = utils.get(utils.getMDCPropertyMap(), marker); 32 | return maybeCorrelationId.isPresent() ? FilterReply.ACCEPT : FilterReply.NEUTRAL; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /logback-censor/src/test/java/com/tersesystems/logback/censor/RegexCensorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.censor; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import org.junit.Test; 16 | 17 | public class RegexCensorTest { 18 | 19 | @Test 20 | public void testCensor() throws Exception { 21 | String replacementText = "*******"; 22 | 23 | RegexCensor censor = new RegexCensor(); 24 | censor.setReplacementText(replacementText); 25 | censor.setRegex("hunter2"); 26 | censor.start(); 27 | 28 | assertThat(censor.censorText("hunter2")).isEqualTo("*******"); 29 | } 30 | 31 | @Test 32 | public void testCensorWithNoMatch() throws Exception { 33 | String replacementText = "*******"; 34 | 35 | RegexCensor censor = new RegexCensor(); 36 | censor.setReplacementText(replacementText); 37 | censor.setRegex("hunter2"); 38 | censor.start(); 39 | 40 | assertThat(censor.censorText("password1")).isEqualTo("password1"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/NanoTimeComponentAppender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.classic; 13 | 14 | import ch.qos.logback.classic.spi.ILoggingEvent; 15 | import com.tersesystems.logback.core.DecoratingAppender; 16 | 17 | /** This appender adds a relative nanotime component to the logging event. */ 18 | public class NanoTimeComponentAppender 19 | extends DecoratingAppender { 20 | @Override 21 | protected IContainerLoggingEvent decorateEvent(ILoggingEvent eventObject) { 22 | IContainerLoggingEvent containerEvent; 23 | if (eventObject instanceof IContainerLoggingEvent) { 24 | containerEvent = (IContainerLoggingEvent) eventObject; 25 | } else { 26 | containerEvent = new ContainerProxyLoggingEvent(eventObject); 27 | } 28 | long nanoTime = System.nanoTime() - NanoTime.start; 29 | containerEvent.putComponent(NanoTimeSupplier.class, () -> nanoTime); 30 | return containerEvent; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /logback-classic/src/test/resources/logback-tapfilter-correlation.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | correlationId 23 | 24 | 25 | 26 | 27 | 28 | 29 | %-5relative %-5level %logger{35} - %msg%n 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/AudioMarkerAppender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | import ch.qos.logback.classic.spi.ILoggingEvent; 14 | import ch.qos.logback.core.AppenderBase; 15 | import java.util.Iterator; 16 | import org.slf4j.Marker; 17 | 18 | public class AudioMarkerAppender extends AppenderBase { 19 | 20 | @Override 21 | protected void append(ILoggingEvent eventObject) { 22 | writePlayerMarkerIfNecessary(eventObject.getMarker()); 23 | } 24 | 25 | private void writePlayerMarkerIfNecessary(Marker marker) { 26 | if (marker != null) { 27 | if (isPlayerMarker(marker)) { 28 | ((Player) marker).play(); 29 | } 30 | 31 | if (marker.hasReferences()) { 32 | for (Iterator i = marker.iterator(); i.hasNext(); ) { 33 | writePlayerMarkerIfNecessary(i.next()); 34 | } 35 | } 36 | } 37 | } 38 | 39 | private static boolean isPlayerMarker(Marker marker) { 40 | return marker instanceof Player; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/AudioMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | import com.tersesystems.logback.classic.TerseBasicMarker; 14 | import java.io.InputStream; 15 | import java.net.URL; 16 | import java.nio.file.Path; 17 | 18 | public class AudioMarker extends TerseBasicMarker implements Player { 19 | 20 | private static final String MARKER_NAME = "TS_AUDIO_MARKER"; 21 | 22 | private final Player player; 23 | 24 | public AudioMarker(URL url) { 25 | super(MARKER_NAME); 26 | player = SimplePlayer.fromURL(url); 27 | } 28 | 29 | public AudioMarker(Path path) { 30 | super(MARKER_NAME); 31 | player = SimplePlayer.fromPath(path); 32 | } 33 | 34 | public AudioMarker(InputStream inputStream) { 35 | super(MARKER_NAME); 36 | player = SimplePlayer.fromInputStream(inputStream); 37 | } 38 | 39 | public AudioMarker(Player player) { 40 | super(MARKER_NAME); 41 | this.player = player; 42 | } 43 | 44 | public void play() { 45 | player.play(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/ContainerProxyLoggingEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.classic; 13 | 14 | import ch.qos.logback.classic.spi.ILoggingEvent; 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | import java.util.Objects; 18 | 19 | /** A logging event that implements a container and proxies another logging event. */ 20 | public class ContainerProxyLoggingEvent extends ProxyLoggingEvent 21 | implements IContainerLoggingEvent { 22 | private Map, Object> components = new HashMap<>(); 23 | 24 | public ContainerProxyLoggingEvent(ILoggingEvent delegate) { 25 | super(delegate); 26 | } 27 | 28 | public void putComponent(Class type, T instance) { 29 | components.put(Objects.requireNonNull(type), instance); 30 | } 31 | 32 | public T getComponent(Class type) { 33 | return type.cast(components.get(type)); 34 | } 35 | 36 | @Override 37 | public boolean hasComponent(Class type) { 38 | return components.containsKey(type); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/PlayerConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | import ch.qos.logback.classic.pattern.ClassicConverter; 14 | import ch.qos.logback.classic.spi.ILoggingEvent; 15 | import java.util.Iterator; 16 | import org.slf4j.Marker; 17 | 18 | public class PlayerConverter extends ClassicConverter { 19 | 20 | @Override 21 | public String convert(ILoggingEvent event) { 22 | writePlayerMarkerIfNecessary(event.getMarker()); 23 | return null; 24 | } 25 | 26 | private void writePlayerMarkerIfNecessary(Marker marker) { 27 | if (marker != null) { 28 | if (isPlayerMarker(marker)) { 29 | ((Player) marker).play(); 30 | } 31 | 32 | if (marker.hasReferences()) { 33 | for (Iterator i = marker.iterator(); i.hasNext(); ) { 34 | writePlayerMarkerIfNecessary(i.next()); 35 | } 36 | } 37 | } 38 | } 39 | 40 | private static boolean isPlayerMarker(Marker marker) { 41 | return marker instanceof Player; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /logback-budget/src/test/java/com.tersesystems.logback.budget/BudgetEvaluatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.budget; 12 | 13 | import ch.qos.logback.classic.Logger; 14 | import ch.qos.logback.classic.LoggerContext; 15 | import ch.qos.logback.classic.joran.JoranConfigurator; 16 | import ch.qos.logback.core.joran.spi.JoranException; 17 | import java.net.URL; 18 | import org.junit.Test; 19 | 20 | public class BudgetEvaluatorTest { 21 | 22 | @Test 23 | public void testBudget() throws JoranException, InterruptedException { 24 | LoggerContext context = new LoggerContext(); 25 | 26 | URL resource = getClass().getResource("/logback-budget.xml"); 27 | JoranConfigurator configurator = new JoranConfigurator(); 28 | configurator.setContext(context); 29 | configurator.doConfigure(resource); 30 | 31 | Logger logger = context.getLogger("some.random.Logger"); 32 | 33 | for (int i = 0; i < 10; i++) { 34 | logger.info("Hello world"); 35 | } 36 | Thread.sleep(1000); 37 | 38 | logger.info("Hello world"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /logback-exception-mapping/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | %-5relative %-5level %logger{35} - %msg%richex{1, 10, exception=[}%n 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /logback-tracing/src/main/java/com/tersesystems/logback/tracing/EventInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.tracing; 13 | 14 | import com.google.auto.value.AutoValue; 15 | 16 | /** 17 | * An event info is a span without a duration. It cannot be used as a parent. 18 | * 19 | *

https://docs.honeycomb.io/working-with-your-data/tracing/send-trace-data/#span-events 20 | */ 21 | @AutoValue 22 | public abstract class EventInfo { 23 | 24 | public static Builder builder() { 25 | return new AutoValue_EventInfo.Builder(); 26 | } 27 | 28 | public abstract Builder toBuilder(); 29 | 30 | @Nullable 31 | public abstract String parentId(); 32 | 33 | public abstract String traceId(); 34 | 35 | public abstract String name(); 36 | 37 | @AutoValue.Builder 38 | public abstract static class Builder { 39 | public abstract Builder setName(String name); 40 | 41 | public abstract Builder setParentId(String parentId); 42 | 43 | public abstract Builder setTraceId(String traceId); 44 | 45 | public abstract EventInfo build(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /logback-correlationid/src/main/java/com/tersesystems/logback/correlationid/CorrelationIdFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.correlationid; 13 | 14 | import ch.qos.logback.classic.spi.ILoggingEvent; 15 | import ch.qos.logback.core.filter.Filter; 16 | import ch.qos.logback.core.spi.FilterReply; 17 | import java.util.Optional; 18 | 19 | public class CorrelationIdFilter extends Filter { 20 | private String mdcKey = "correlation_id"; 21 | 22 | public String getMdcKey() { 23 | return mdcKey; 24 | } 25 | 26 | public void setMdcKey(String mdcKey) { 27 | this.mdcKey = mdcKey; 28 | } 29 | 30 | protected CorrelationIdUtils utils; 31 | 32 | @Override 33 | public void start() { 34 | super.start(); 35 | utils = new CorrelationIdUtils(mdcKey); 36 | } 37 | 38 | @Override 39 | public FilterReply decide(ILoggingEvent event) { 40 | Optional maybeCorrelationId = utils.get(event.getMDCPropertyMap(), event.getMarker()); 41 | return maybeCorrelationId.isPresent() ? FilterReply.ACCEPT : FilterReply.DENY; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /logback-exception-mapping-providers/src/test/resources/logback-with-exception-mapping.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 15 | 16 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | [%-5level] %logger{15} - %msg%n%xException{10} 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /logback-tracing/src/main/java/com/tersesystems/logback/tracing/LinkInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.tracing; 13 | 14 | import com.google.auto.value.AutoValue; 15 | 16 | /** https://docs.honeycomb.io/working-with-your-data/tracing/send-trace-data/#links */ 17 | @AutoValue 18 | public abstract class LinkInfo { 19 | 20 | public static Builder builder() { 21 | return new AutoValue_LinkInfo.Builder(); 22 | } 23 | 24 | public abstract Builder toBuilder(); 25 | 26 | @Nullable 27 | public abstract String parentId(); 28 | 29 | public abstract String traceId(); 30 | 31 | public abstract String linkedSpanId(); 32 | 33 | public abstract String linkedTraceId(); 34 | 35 | @AutoValue.Builder 36 | public abstract static class Builder { 37 | 38 | public abstract Builder setLinkedSpanId(String linkedSpanId); 39 | 40 | public abstract Builder setLinkedTraceId(String linkedTraceId); 41 | 42 | public abstract Builder setParentId(String parentId); 43 | 44 | public abstract Builder setTraceId(String traceId); 45 | 46 | public abstract LinkInfo build(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /logback-compress-encoder/src/test/java/com/tersesystems/logback/compress/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.compress; 12 | 13 | import java.io.ByteArrayOutputStream; 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | 17 | public class Utils { 18 | 19 | public static byte[] readAllBytes(InputStream inputStream) throws IOException { 20 | final int bufLen = 4 * 0x400; // 4KB 21 | byte[] buf = new byte[bufLen]; 22 | int readLen; 23 | IOException exception = null; 24 | 25 | try { 26 | try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { 27 | while ((readLen = inputStream.read(buf, 0, bufLen)) != -1) 28 | outputStream.write(buf, 0, readLen); 29 | 30 | return outputStream.toByteArray(); 31 | } 32 | } catch (IOException e) { 33 | exception = e; 34 | throw e; 35 | } finally { 36 | if (exception == null) inputStream.close(); 37 | else 38 | try { 39 | inputStream.close(); 40 | } catch (IOException e) { 41 | exception.addSuppressed(e); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /logback-budget/src/main/java/com/tersesystems/logback/budget/BudgetRule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.budget; 12 | 13 | import org.apache.commons.lang3.builder.ToStringBuilder; 14 | 15 | public class BudgetRule { 16 | 17 | private String name; 18 | private int threshold; 19 | private long interval; 20 | private String timeUnit; 21 | 22 | public BudgetRule() {} 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public int getThreshold() { 33 | return threshold; 34 | } 35 | 36 | public void setThreshold(int threshold) { 37 | this.threshold = threshold; 38 | } 39 | 40 | public long getInterval() { 41 | return interval; 42 | } 43 | 44 | public void setInterval(long interval) { 45 | this.interval = interval; 46 | } 47 | 48 | public String getTimeUnit() { 49 | return timeUnit; 50 | } 51 | 52 | public void setTimeUnit(String timeUnit) { 53 | this.timeUnit = timeUnit; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return ToStringBuilder.reflectionToString(this); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /logback-censor/src/test/resources/test1.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | [CENSORED BY CENSOR1] 23 | hunter1 24 | 25 | 26 | 27 | [CENSORED BY CENSOR2] 28 | hunter2 29 | 30 | 31 | 32 | 33 | %censor(%msg){censor-name1}%n 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /logback-censor/src/test/resources/test2.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | [CENSORED BY CENSOR1] 23 | hunter1 24 | 25 | 26 | 27 | [CENSORED BY CENSOR2] 28 | hunter2 29 | 30 | 31 | 32 | 33 | %censor(%msg){censor-name2}%n 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /logback-classic/src/test/java/com/tersesystems/logback/classic/EnabledFilterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import ch.qos.logback.classic.spi.ILoggingEvent; 14 | import ch.qos.logback.classic.spi.LoggingEventVO; 15 | import ch.qos.logback.core.spi.FilterReply; 16 | import com.tersesystems.logback.core.EnabledFilter; 17 | import org.assertj.core.api.Assertions; 18 | import org.junit.Test; 19 | 20 | public class EnabledFilterTest { 21 | @Test 22 | public void testFilterFalse() { 23 | EnabledFilter enabledFilter = new EnabledFilter(); 24 | enabledFilter.setEnabled(false); 25 | enabledFilter.start(); 26 | 27 | ILoggingEvent loggingEvent = new LoggingEventVO(); 28 | 29 | Assertions.assertThat(enabledFilter.decide(loggingEvent)).isEqualTo(FilterReply.DENY); 30 | } 31 | 32 | @Test 33 | public void testFilterTrue() { 34 | EnabledFilter enabledFilter = new EnabledFilter(); 35 | enabledFilter.setEnabled(true); 36 | enabledFilter.start(); 37 | 38 | ILoggingEvent loggingEvent = new LoggingEventVO(); 39 | 40 | Assertions.assertThat(enabledFilter.decide(loggingEvent)).isEqualTo(FilterReply.NEUTRAL); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /logback-exception-mapping/src/main/java/com/tersesystems/logback/exceptionmapping/KeyValueExceptionProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.exceptionmapping; 12 | 13 | import java.util.Objects; 14 | 15 | public class KeyValueExceptionProperty implements ExceptionProperty { 16 | 17 | private final String key; 18 | private final String value; 19 | 20 | KeyValueExceptionProperty(String key, String value) { 21 | this.key = key; 22 | this.value = value; 23 | } 24 | 25 | public String getKey() { 26 | return key; 27 | } 28 | 29 | public String getValue() { 30 | return value; 31 | } 32 | 33 | @Override 34 | public boolean equals(Object o) { 35 | if (this == o) return true; 36 | if (o == null || getClass() != o.getClass()) return false; 37 | KeyValueExceptionProperty that = (KeyValueExceptionProperty) o; 38 | return key.equals(that.key) && value.equals(that.value); 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | return Objects.hash(key, value); 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return String.format("KeyValueExceptionProperty(key=%s, value=%s)", key, getValue()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/FilePlayer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | import ch.qos.logback.core.spi.ContextAwareBase; 14 | import ch.qos.logback.core.spi.LifeCycle; 15 | import java.nio.file.Files; 16 | import java.nio.file.Path; 17 | import java.nio.file.Paths; 18 | 19 | public class FilePlayer extends ContextAwareBase implements Player, LifeCycle { 20 | 21 | private String file; 22 | private Path path; 23 | private volatile boolean started = false; 24 | 25 | public FilePlayer() {} 26 | 27 | public void setFile(String file) { 28 | this.file = file; 29 | } 30 | 31 | @Override 32 | public void play() { 33 | SimplePlayer.fromPath(path).play(); 34 | } 35 | 36 | @Override 37 | public void start() { 38 | path = Paths.get(file); 39 | if (Files.exists(path)) { 40 | started = true; 41 | } else { 42 | addError(String.format("Path %s does not exist!", path)); 43 | started = false; 44 | } 45 | } 46 | 47 | @Override 48 | public void stop() { 49 | path = null; 50 | started = false; 51 | } 52 | 53 | @Override 54 | public boolean isStarted() { 55 | return started; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /logback-classic/src/test/java/com/tersesystems/logback/classic/TerseHighlightConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import ch.qos.logback.classic.Level; 16 | import ch.qos.logback.classic.LoggerContext; 17 | import ch.qos.logback.classic.spi.LoggingEvent; 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | import org.junit.Test; 21 | 22 | public class TerseHighlightConverterTest { 23 | 24 | @Test 25 | public void testHighlighter() { 26 | TerseHighlightConverter converter = new TerseHighlightConverter(); 27 | LoggerContext context = new LoggerContext(); 28 | converter.setContext(context); 29 | Map properties = new HashMap<>(); 30 | properties.put("info", "red"); 31 | context.putObject(TerseHighlightConverter.HIGHLIGHT_CTX_KEY, properties); 32 | converter.start(); 33 | LoggingEvent infoEvent = 34 | new LoggingEvent("fcqn", context.getLogger("fcqn"), Level.INFO, "info", null, null); 35 | String actual = converter.convert(infoEvent); 36 | 37 | assertThat(actual).contains(TerseHighlightConverter.Color.valueOf("RED").code); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /logback-typesafe-config/src/test/java/com/tersesystems/logback/typesafeconfig/ConfigListConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.typesafeconfig; 12 | 13 | import static com.tersesystems.logback.typesafeconfig.ConfigConstants.TYPESAFE_CONFIG_CTX_KEY; 14 | import static org.assertj.core.api.Assertions.assertThat; 15 | 16 | import ch.qos.logback.classic.LoggerContext; 17 | import com.typesafe.config.Config; 18 | import com.typesafe.config.ConfigFactory; 19 | import java.util.Arrays; 20 | import org.junit.Test; 21 | 22 | public class ConfigListConverterTest { 23 | 24 | @Test 25 | public void testConversion() { 26 | LoggerContext context = new LoggerContext(); 27 | ConfigListConverter configValueConverter = new ConfigListConverter(); 28 | 29 | Config config = ConfigFactory.parseString("some.property.name=[one,two,three]"); 30 | context.putObject(TYPESAFE_CONFIG_CTX_KEY, config); 31 | 32 | configValueConverter.setContext(context); 33 | configValueConverter.setOptionList(Arrays.asList("some.property.name", "1")); 34 | configValueConverter.start(); 35 | 36 | String actual = configValueConverter.convert(null); 37 | 38 | assertThat(actual).isEqualTo("two"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /logback-uniqueid-appender/src/test/resources/logback-with-uniqueid-appender.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | LIST 22 | 23 | 24 | 25 | 26 | %-5relative %-5level %uniqueId %logger{35} - %msg%n 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /logback-typesafe-config/src/main/java/com/tersesystems/logback/typesafeconfig/ConfigConversion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.typesafeconfig; 12 | 13 | import ch.qos.logback.core.spi.ContextAware; 14 | import com.typesafe.config.Config; 15 | import com.typesafe.config.ConfigException; 16 | import com.typesafe.config.ConfigValue; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | import java.util.Set; 20 | 21 | public interface ConfigConversion extends ContextAware { 22 | 23 | default Map configAsMap(Config levelsConfig) { 24 | Map levelsMap = new HashMap<>(); 25 | Set> levelsEntrySet = levelsConfig.entrySet(); 26 | for (Map.Entry entry : levelsEntrySet) { 27 | String name = entry.getKey(); 28 | try { 29 | String levelFromConfig = entry.getValue().unwrapped().toString(); 30 | levelsMap.put(name, levelFromConfig); 31 | } catch (ConfigException.Missing e) { 32 | addInfo("No custom setting found for " + name + " in config, ignoring"); 33 | } catch (Exception e) { 34 | addError("Unexpected exception resolving " + name, e); 35 | } 36 | } 37 | return levelsMap; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/SLF4JBridgeHandlerAction.java: -------------------------------------------------------------------------------- 1 | package com.tersesystems.logback.classic; 2 | 3 | import ch.qos.logback.core.joran.action.Action; 4 | import ch.qos.logback.core.joran.spi.ActionException; 5 | import ch.qos.logback.core.joran.spi.InterpretationContext; 6 | import org.slf4j.bridge.SLF4JBridgeHandler; 7 | import org.xml.sax.Attributes; 8 | 9 | /** 10 | * Provides SLF4JBridgeHandler installation as an action. This is useful because it means you don't 11 | * have to add custom code to your main method, and can completely initialize JUL by adding this. 12 | * 13 | *

Easiest way to do this is to use a custom rule: 14 | * 15 | *

"<newRule pattern="configuration/slf4jBridgeHandler" 16 | * actionClass="com.tersesystems.logback.classic.SLF4JBridgeHandlerAction"/>" 17 | * 18 | *

and then call it: 19 | * 20 | *

"<slf4jBridgeHandler/>" 21 | * 22 | *

You should use this in conjunction with the "LevelChangePropagator": 23 | * 24 | *

"<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>" 25 | */ 26 | public class SLF4JBridgeHandlerAction extends Action { 27 | 28 | @Override 29 | public void begin(InterpretationContext ic, String name, Attributes attributes) 30 | throws ActionException { 31 | SLF4JBridgeHandler.removeHandlersForRootLogger(); 32 | SLF4JBridgeHandler.install(); 33 | } 34 | 35 | @Override 36 | public void end(InterpretationContext ic, String name) throws ActionException {} 37 | } 38 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/functional/GetSiftedAppenderFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic.functional; 12 | 13 | import ch.qos.logback.classic.sift.SiftingAppender; 14 | import ch.qos.logback.classic.spi.ILoggingEvent; 15 | import ch.qos.logback.core.Appender; 16 | import ch.qos.logback.core.sift.AppenderTracker; 17 | import java.util.Optional; 18 | import java.util.function.Function; 19 | 20 | public class GetSiftedAppenderFunction implements Function> { 21 | 22 | private final String key; 23 | 24 | public GetSiftedAppenderFunction(String key) { 25 | this.key = key; 26 | } 27 | 28 | @SuppressWarnings("unchecked") 29 | @Override 30 | public Optional apply(SiftingAppender siftingAppender) { 31 | AppenderTracker appenderTracker = siftingAppender.getAppenderTracker(); 32 | try { 33 | return Optional.ofNullable((A) appenderTracker.find(key)); 34 | } catch (ClassCastException e) { 35 | return Optional.empty(); 36 | } 37 | } 38 | 39 | public static > GetSiftedAppenderFunction create( 40 | String key) { 41 | return new GetSiftedAppenderFunction(key); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /logback-jdbc-appender/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | ${jdbc.driver} 22 | ${jdbc.url} 23 | ${jdbc.username} 24 | ${jdbc.password} 25 | 26 | 27 | ${jdbc.createStatements} 28 | ${jdbc.insertStatement} 29 | ${jdbc.reaperStatement} 30 | ${jdbc.reaperSchedule} 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /logback-audio/src/test/java/com/tersesystems/logback/audio/TestNested.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | import ch.qos.logback.classic.Logger; 14 | import ch.qos.logback.classic.LoggerContext; 15 | import ch.qos.logback.classic.joran.JoranConfigurator; 16 | import ch.qos.logback.core.joran.spi.JoranException; 17 | import java.net.URL; 18 | import org.junit.Test; 19 | 20 | public class TestNested { 21 | 22 | @Test 23 | public void testLogger() throws JoranException, InterruptedException { 24 | LoggerContext context = new LoggerContext(); 25 | 26 | URL resource = getClass().getResource("/logback-with-nested-appender.xml"); 27 | JoranConfigurator configurator = new JoranConfigurator(); 28 | configurator.setContext(context); 29 | configurator.doConfigure(resource); 30 | 31 | Logger logger = context.getLogger("some.random.Logger"); 32 | 33 | for (int i = 0; i < 1; i++) { 34 | logger.trace("TRACE"); 35 | } 36 | 37 | for (int i = 0; i < 2; i++) { 38 | logger.debug("DEBUG"); 39 | } 40 | 41 | for (int i = 0; i < 2; i++) { 42 | logger.info("INFO"); 43 | } 44 | 45 | for (int i = 0; i < 2; i++) { 46 | logger.warn("WARN"); 47 | } 48 | 49 | logger.error("ERROR"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /logback-exception-mapping/src/main/java/com/tersesystems/logback/exceptionmapping/ExceptionHierarchyIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.exceptionmapping; 12 | 13 | import java.util.Iterator; 14 | import java.util.Spliterator; 15 | import java.util.Spliterators; 16 | import java.util.stream.Stream; 17 | import java.util.stream.StreamSupport; 18 | 19 | public class ExceptionHierarchyIterator implements Iterator> { 20 | private Class clazz; 21 | 22 | ExceptionHierarchyIterator(Class clazz) { 23 | this.clazz = clazz; 24 | } 25 | 26 | @Override 27 | public boolean hasNext() { 28 | return clazz != null; 29 | } 30 | 31 | @SuppressWarnings("unchecked") 32 | @Override 33 | public Class next() { 34 | Class oldClass = clazz; 35 | if (clazz != null) { 36 | clazz = clazz.getSuperclass(); 37 | } 38 | return oldClass; 39 | } 40 | 41 | @SuppressWarnings("unchecked") 42 | public Stream> stream() { 43 | Spliterator spliterator = Spliterators.spliteratorUnknownSize(this, 0); 44 | return (Stream>) StreamSupport.stream(spliterator, false); 45 | } 46 | 47 | public static ExceptionHierarchyIterator create(Class clazz) { 48 | return new ExceptionHierarchyIterator(clazz); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /logback-exception-mapping/src/main/java/com/tersesystems/logback/exceptionmapping/ExceptionCauseIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.exceptionmapping; 12 | 13 | import java.util.Iterator; 14 | import java.util.Spliterator; 15 | import java.util.Spliterators; 16 | import java.util.stream.Stream; 17 | import java.util.stream.StreamSupport; 18 | 19 | public class ExceptionCauseIterator implements Iterator { 20 | private Throwable throwable; 21 | 22 | ExceptionCauseIterator(Throwable throwable) { 23 | this.throwable = throwable; 24 | } 25 | 26 | @Override 27 | public boolean hasNext() { 28 | return throwable != null; 29 | } 30 | 31 | @SuppressWarnings("unchecked") 32 | @Override 33 | public Throwable next() { 34 | Throwable oldThrowable = throwable; 35 | if (throwable != null) { 36 | throwable = throwable.getCause(); 37 | } 38 | return oldThrowable; 39 | } 40 | 41 | @SuppressWarnings("unchecked") 42 | public Stream stream() { 43 | Spliterator spliterator = Spliterators.spliteratorUnknownSize(this, 0); 44 | return (Stream) StreamSupport.stream(spliterator, false); 45 | } 46 | 47 | public static ExceptionCauseIterator create(Throwable throwable) { 48 | return new ExceptionCauseIterator(throwable); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /logback-exception-mapping/src/main/java/com/tersesystems/logback/exceptionmapping/ExceptionMappingRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.exceptionmapping; 12 | 13 | import java.util.*; 14 | import java.util.function.Function; 15 | 16 | public interface ExceptionMappingRegistry { 17 | 18 | void register(Map> mappers); 19 | 20 | void register(ClassLoader classLoader, Map> mappers); 21 | 22 | void register(String className, String... methodNames); 23 | 24 | void register(ClassLoader classLoader, String className, String... methodNames); 25 | 26 | void register(Class exceptionClass, String... propertyNames); 27 | 28 | void register( 29 | Class exceptionClass, Function> f); 30 | 31 | void register(String className, Function> f); 32 | 33 | void register(ExceptionMapping mapper); 34 | 35 | List apply(Throwable e); 36 | 37 | Iterator iterator(); 38 | 39 | ExceptionMapping get(String name); 40 | 41 | boolean contains(ExceptionMapping exceptionMapping); 42 | 43 | boolean contains(String name); 44 | 45 | boolean remove(ExceptionMapping exceptionMapping); 46 | 47 | boolean remove(String name); 48 | } 49 | -------------------------------------------------------------------------------- /logback-bytebuddy/src/main/java/com/tersesystems/logback/bytebuddy/MethodInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.bytebuddy; 12 | 13 | import java.util.Objects; 14 | 15 | /** 16 | * Provides line number and source at implementation time without the overhead of fillInStackTrace. 17 | */ 18 | public class MethodInfo { 19 | final String methodName; 20 | final String descriptor; 21 | public final String source; 22 | private int startLine; 23 | private int endLine; 24 | 25 | MethodInfo(String methodName, String descriptor, String source) { 26 | this.methodName = Objects.requireNonNull(methodName); 27 | this.descriptor = descriptor; 28 | this.source = source; 29 | } 30 | 31 | public void setStartLine(int line) { 32 | this.startLine = line; 33 | } 34 | 35 | public void setEndLine(int line) { 36 | this.endLine = line; 37 | } 38 | 39 | public int getStartLine() { 40 | return startLine; 41 | } 42 | 43 | public int getEndLine() { 44 | return endLine; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "MethodInfo{" 50 | + "methodName='" 51 | + methodName 52 | + '\'' 53 | + ", descriptor='" 54 | + descriptor 55 | + '\'' 56 | + ", source='" 57 | + source 58 | + '\'' 59 | + '}'; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /logback-uniqueid-appender/src/main/java/com/tersesystems/logback/uniqueid/UniqueIdComponentAppender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.uniqueid; 12 | 13 | import ch.qos.logback.classic.spi.ILoggingEvent; 14 | import com.tersesystems.logback.classic.ContainerProxyLoggingEvent; 15 | import com.tersesystems.logback.classic.IContainerLoggingEvent; 16 | import com.tersesystems.logback.core.DecoratingAppender; 17 | 18 | public class UniqueIdComponentAppender 19 | extends DecoratingAppender { 20 | 21 | private IdGenerator idGenerator = new FlakeIdGenerator(); 22 | 23 | public IdGenerator getIdGenerator() { 24 | return idGenerator; 25 | } 26 | 27 | public void setIdGenerator(IdGenerator idGenerator) { 28 | this.idGenerator = idGenerator; 29 | } 30 | 31 | @Override 32 | protected IContainerLoggingEvent decorateEvent(ILoggingEvent eventObject) { 33 | IContainerLoggingEvent containerEvent; 34 | if (eventObject instanceof IContainerLoggingEvent) { 35 | containerEvent = (IContainerLoggingEvent) eventObject; 36 | } else { 37 | containerEvent = new ContainerProxyLoggingEvent(eventObject); 38 | } 39 | String uniqueId = idGenerator.generateId(); 40 | containerEvent.putComponent(UniqueIdProvider.class, () -> uniqueId); 41 | return containerEvent; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/ResourcePlayer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | import ch.qos.logback.core.spi.ContextAwareBase; 14 | import ch.qos.logback.core.spi.LifeCycle; 15 | import java.net.URL; 16 | 17 | public class ResourcePlayer extends ContextAwareBase implements Player, LifeCycle { 18 | 19 | private String resource; 20 | private URL resourceURL; 21 | private volatile boolean started = false; 22 | 23 | public ResourcePlayer() {} 24 | 25 | public void setResource(String resource) { 26 | this.resource = resource; 27 | } 28 | 29 | @Override 30 | public void play() { 31 | try { 32 | SimplePlayer.fromURL(resourceURL).play(); 33 | } catch (Exception e) { 34 | addError(String.format("Cannot play resource %s", resourceURL), e); 35 | } 36 | } 37 | 38 | @Override 39 | public void start() { 40 | resourceURL = getClass().getResource(resource); 41 | if (resourceURL != null) { 42 | started = true; 43 | } else { 44 | addError(String.format("Resource %s does not exist!", resource)); 45 | started = false; 46 | } 47 | } 48 | 49 | @Override 50 | public void stop() { 51 | resource = null; 52 | started = false; 53 | } 54 | 55 | @Override 56 | public boolean isStarted() { 57 | return started; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /logback-core/src/main/java/com/tersesystems/logback/core/DefaultAppenderAttachable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.core; 12 | 13 | import ch.qos.logback.core.Appender; 14 | import ch.qos.logback.core.spi.AppenderAttachable; 15 | import ch.qos.logback.core.spi.AppenderAttachableImpl; 16 | import java.util.Iterator; 17 | 18 | public interface DefaultAppenderAttachable extends AppenderAttachable { 19 | 20 | AppenderAttachableImpl appenderAttachableImpl(); 21 | 22 | default void addAppender(Appender newAppender) { 23 | appenderAttachableImpl().addAppender(newAppender); 24 | } 25 | 26 | default Iterator> iteratorForAppenders() { 27 | return appenderAttachableImpl().iteratorForAppenders(); 28 | } 29 | 30 | default Appender getAppender(String name) { 31 | return appenderAttachableImpl().getAppender(name); 32 | } 33 | 34 | default boolean isAttached(Appender eAppender) { 35 | return appenderAttachableImpl().isAttached(eAppender); 36 | } 37 | 38 | default void detachAndStopAllAppenders() { 39 | appenderAttachableImpl().detachAndStopAllAppenders(); 40 | } 41 | 42 | default boolean detachAppender(Appender eAppender) { 43 | return appenderAttachableImpl().detachAppender(eAppender); 44 | } 45 | 46 | default boolean detachAppender(String name) { 47 | return appenderAttachableImpl().detachAppender(name); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /logback-exception-mapping/src/main/java/com/tersesystems/logback/exceptionmapping/ExceptionProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.exceptionmapping; 12 | 13 | import java.util.Arrays; 14 | 15 | public interface ExceptionProperty { 16 | 17 | public static ExceptionProperty create(String name, String value) { 18 | return new KeyValueExceptionProperty(name, value); 19 | } 20 | 21 | public static ExceptionProperty create(String name, Object value) { 22 | return new KeyValueExceptionProperty(name, toString(value)); 23 | } 24 | 25 | static String toString(Object value) { 26 | if (value instanceof boolean[]) return Arrays.toString((boolean[]) value); 27 | if (value instanceof byte[]) return Arrays.toString((byte[]) value); 28 | if (value instanceof short[]) return Arrays.toString((short[]) value); 29 | if (value instanceof char[]) return Arrays.toString((char[]) value); 30 | if (value instanceof int[]) return Arrays.toString((int[]) value); 31 | if (value instanceof long[]) return Arrays.toString((long[]) value); 32 | if (value instanceof float[]) return Arrays.toString((float[]) value); 33 | if (value instanceof double[]) return Arrays.toString((double[]) value); 34 | if (value instanceof Object[]) return Arrays.deepToString((Object[]) value); 35 | if (value == null) { 36 | return "null"; 37 | } 38 | return value.toString(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /logback-censor/src/test/resources/test3.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | hunter3 23 | [CENSOR3] 24 | 25 | 26 | 27 | hunter4 28 | [CENSOR4] 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /logback-tracing/src/main/java/com/tersesystems/logback/tracing/LinkMarkerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.tracing; 13 | 14 | import net.logstash.logback.marker.LogstashMarker; 15 | import net.logstash.logback.marker.Markers; 16 | 17 | public class LinkMarkerFactory { 18 | 19 | // Java API 20 | public LogstashMarker create(LinkInfo linkInfo) { 21 | LogstashMarker[] markers = generateMarkers(linkInfo); 22 | return Markers.aggregate(markers); 23 | } 24 | 25 | // Scala API 26 | public LogstashMarker apply(LinkInfo linkInfo) { 27 | return create(linkInfo); 28 | } 29 | 30 | protected LogstashMarker[] generateMarkers(LinkInfo linkInfo) { 31 | // XXX Should have a field name registry that lets you define field names by dataset 32 | LogstashMarker traceIdMarker = Markers.append("trace.trace_id", linkInfo.traceId()); 33 | LogstashMarker parentIdMarker = Markers.append("trace.parent_id", linkInfo.parentId()); 34 | LogstashMarker linkedSpanMarker = Markers.append("trace.link.span_id", linkInfo.linkedSpanId()); 35 | LogstashMarker linkedTraceMarker = 36 | Markers.append("trace.link.trace_id", linkInfo.linkedTraceId()); 37 | LogstashMarker spanTypeMarker = Markers.append("meta.span_type", "link"); 38 | LogstashMarker[] markers = { 39 | parentIdMarker, traceIdMarker, linkedSpanMarker, linkedTraceMarker, spanTypeMarker 40 | }; 41 | return markers; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /logback-postgresjson-appender/src/main/java/com/tersesystems/logback/postgresjson/PostgresJsonAppender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.postgresjson; 12 | 13 | import ch.qos.logback.classic.spi.ILoggingEvent; 14 | import com.tersesystems.logback.jdbc.JDBCAppender; 15 | import java.nio.charset.StandardCharsets; 16 | import java.sql.PreparedStatement; 17 | import java.sql.SQLException; 18 | import java.util.concurrent.atomic.LongAdder; 19 | import org.postgresql.util.PGobject; 20 | 21 | /** Extends the JDBC appender to write out Postgres JSON object. */ 22 | public class PostgresJsonAppender extends JDBCAppender { 23 | 24 | private String objectType = "json"; 25 | 26 | public String getObjectType() { 27 | return objectType; 28 | } 29 | 30 | public void setObjectType(String objectType) { 31 | this.objectType = objectType; 32 | } 33 | 34 | @Override 35 | public void start() { 36 | super.start(); 37 | setDriver("org.postgresql.Driver"); 38 | } 39 | 40 | @Override 41 | protected void insertEvent(ILoggingEvent event, LongAdder adder, PreparedStatement statement) 42 | throws SQLException { 43 | PGobject jsonObject = new PGobject(); 44 | jsonObject.setType(getObjectType()); 45 | byte[] bytes = getEncoder().encode(event); 46 | jsonObject.setValue(new String(bytes, StandardCharsets.UTF_8)); 47 | statement.setObject(adder.intValue(), jsonObject); 48 | adder.increment(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /logback-tracing/src/main/java/com/tersesystems/logback/tracing/EventMarkerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.tracing; 13 | 14 | import net.logstash.logback.marker.LogstashMarker; 15 | import net.logstash.logback.marker.Markers; 16 | 17 | /** 18 | * This is a marker factory that adds several logstash markers to create a span in Honeycomb format. 19 | */ 20 | public class EventMarkerFactory { 21 | 22 | // Java API 23 | public LogstashMarker create(EventInfo eventInfo) { 24 | LogstashMarker[] markers = generateMarkers(eventInfo); 25 | return Markers.aggregate(markers); 26 | } 27 | 28 | // Scala API 29 | public LogstashMarker apply(EventInfo eventInfo) { 30 | return create(eventInfo); 31 | } 32 | 33 | protected LogstashMarker[] generateMarkers(EventInfo eventInfo) { 34 | // XXX Should have a field name registry that lets you define field names by dataset 35 | LogstashMarker nameMarker = Markers.append("name", eventInfo.name()); 36 | LogstashMarker parentIdMarker = Markers.append("trace.parent_id", eventInfo.parentId()); 37 | LogstashMarker traceIdMarker = Markers.append("trace.trace_id", eventInfo.traceId()); 38 | LogstashMarker spanTypeMarker = Markers.append("meta.span_type", "span_event"); 39 | // Don't include the timestamp marker, as it'll be handled by Logback 40 | LogstashMarker[] markers = {nameMarker, parentIdMarker, traceIdMarker, spanTypeMarker}; 41 | return markers; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/ChangeLogLevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import ch.qos.logback.classic.Level; 14 | import ch.qos.logback.classic.Logger; 15 | import org.slf4j.ILoggerFactory; 16 | import org.slf4j.LoggerFactory; 17 | 18 | /** Provide a way to change the logging level dynamically in Logback. */ 19 | public class ChangeLogLevel { 20 | 21 | private final ILoggerFactory loggerFactory; 22 | 23 | public ChangeLogLevel() { 24 | this(LoggerFactory.getILoggerFactory()); 25 | } 26 | 27 | public ChangeLogLevel(ILoggerFactory loggerFactory) { 28 | this.loggerFactory = loggerFactory; 29 | } 30 | 31 | public void changeLogLevel(String loggerName, String levelName) { 32 | changeLogLevel(loggerFactory.getLogger(loggerName), levelName); 33 | } 34 | 35 | public final void changeLogLevel(String loggerName, int levelNumber) { 36 | changeLogLevel(loggerFactory.getLogger(loggerName), levelNumber); 37 | } 38 | 39 | public final void changeLogLevel(org.slf4j.Logger logger, String levelName) { 40 | Logger logbackLogger = (Logger) logger; 41 | Level level = Level.toLevel(levelName); 42 | logbackLogger.setLevel(level); 43 | } 44 | 45 | public final void changeLogLevel(org.slf4j.Logger logger, int levelNumber) { 46 | Logger logbackLogger = (Logger) logger; 47 | Level level = Level.toLevel(levelNumber); 48 | logbackLogger.setLevel(level); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /logback-turbomarker/src/test/java/com/tersesystems/logback/turbomarker/LDMarkerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | 12 | package com.tersesystems.logback.turbomarker; 13 | 14 | import static java.util.Objects.requireNonNull; 15 | 16 | import ch.qos.logback.core.spi.FilterReply; 17 | import com.launchdarkly.client.LDClientInterface; 18 | import com.launchdarkly.client.LDUser; 19 | 20 | public class LDMarkerFactory { 21 | private final LaunchDarklyDecider decider; 22 | 23 | public LDMarkerFactory(LDClientInterface client) { 24 | this.decider = new LaunchDarklyDecider(requireNonNull(client)); 25 | } 26 | 27 | public LDMarker create(String featureFlag, LDUser user) { 28 | return new LDMarker(featureFlag, user, decider); 29 | } 30 | 31 | static class LaunchDarklyDecider implements MarkerContextDecider { 32 | private final LDClientInterface ldClient; 33 | 34 | LaunchDarklyDecider(LDClientInterface ldClient) { 35 | this.ldClient = ldClient; 36 | } 37 | 38 | @Override 39 | public FilterReply apply(ContextAwareTurboMarker marker, LDUser ldUser) { 40 | return ldClient.boolVariation(marker.getName(), ldUser, false) 41 | ? FilterReply.ACCEPT 42 | : FilterReply.NEUTRAL; 43 | } 44 | } 45 | 46 | public static class LDMarker extends ContextAwareTurboMarker { 47 | LDMarker(String name, LDUser context, ContextAwareTurboFilterDecider decider) { 48 | super(name, context, decider); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | pluginManagement { 12 | repositories { 13 | jcenter() 14 | maven { url 'https://plugins.gradle.org/m2/' } 15 | } 16 | } 17 | 18 | rootProject.name = 'terse-logback' 19 | 20 | def includeProject = { String projectName -> 21 | File projectDir = new File(settingsDir, projectName) 22 | String buildFileName = "${projectName}.gradle" 23 | 24 | assert projectDir.isDirectory() 25 | assert new File(projectDir, buildFileName).isFile() 26 | 27 | include projectName 28 | project(":${projectName}").projectDir = projectDir 29 | project(":${projectName}").buildFileName = buildFileName 30 | } 31 | 32 | includeProject 'logback-bytebuddy' 33 | includeProject 'logback-censor' 34 | includeProject 'logback-core' 35 | includeProject 'logback-correlationid' 36 | includeProject 'logback-classic' 37 | includeProject 'logback-typesafe-config' 38 | includeProject 'logback-audio' 39 | includeProject 'logback-compress-encoder' 40 | includeProject 'logback-budget' 41 | includeProject 'logback-uniqueid-appender' 42 | includeProject 'logback-exception-mapping' 43 | includeProject 'logback-exception-mapping-providers' 44 | includeProject 'logback-turbomarker' 45 | includeProject 'logback-tracing' 46 | includeProject 'logback-jdbc-appender' 47 | includeProject 'logback-honeycomb-client' 48 | includeProject 'logback-honeycomb-appender' 49 | includeProject 'logback-honeycomb-okhttp' 50 | includeProject 'logback-postgresjson-appender' 51 | 52 | //includeProject 'guide' 53 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/PlayMethods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | import java.io.IOException; 14 | import java.util.function.Supplier; 15 | import javax.sound.sampled.*; 16 | 17 | public interface PlayMethods { 18 | 19 | default void play(Supplier supplier) { 20 | // https://docs.oracle.com/javase/tutorial/sound/playing.html 21 | try (final AudioInputStream in = supplier.get()) { 22 | AudioFormat baseFormat = in.getFormat(); 23 | AudioFormat targetFormat = 24 | new AudioFormat( 25 | AudioFormat.Encoding.PCM_SIGNED, 26 | baseFormat.getSampleRate(), 27 | 16, 28 | baseFormat.getChannels(), 29 | baseFormat.getChannels() * 2, 30 | baseFormat.getSampleRate(), 31 | false); 32 | try (final AudioInputStream dataIn = AudioSystem.getAudioInputStream(targetFormat, in)) { 33 | DataLine.Info info = new DataLine.Info(Clip.class, targetFormat); 34 | Clip clip = (Clip) AudioSystem.getLine(info); 35 | if (clip != null) { 36 | clip.addLineListener( 37 | event -> { 38 | if (event.getType() == LineEvent.Type.STOP) clip.close(); 39 | }); 40 | 41 | clip.open(dataIn); 42 | clip.start(); 43 | } 44 | } 45 | } catch (LineUnavailableException | IOException e) { 46 | throw new IllegalStateException(e); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /logback-bytebuddy/src/main/java/com/tersesystems/logback/bytebuddy/MethodInfoLookup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.bytebuddy; 12 | 13 | import java.util.HashSet; 14 | import java.util.Objects; 15 | import java.util.Optional; 16 | import java.util.Set; 17 | import java.util.concurrent.ConcurrentHashMap; 18 | import java.util.concurrent.ConcurrentMap; 19 | import java.util.function.Predicate; 20 | 21 | public class MethodInfoLookup { 22 | 23 | private final ConcurrentMap> classNameToMethods = 24 | new ConcurrentHashMap<>(); 25 | 26 | public static MethodInfoLookup getInstance() { 27 | return SingletonHolder.instance; 28 | } 29 | 30 | static class SingletonHolder { 31 | public static MethodInfoLookup instance = new MethodInfoLookup(); 32 | } 33 | 34 | public void add(String className, MethodInfo methodInfo) { 35 | Set infos = classNameToMethods.computeIfAbsent(className, k -> new HashSet<>()); 36 | infos.add(methodInfo); 37 | } 38 | 39 | public Optional find(String className, String methodName, String descriptor) { 40 | Set infos = classNameToMethods.computeIfAbsent(className, k -> new HashSet<>()); 41 | return infos.stream().filter(matchingInfo(methodName, descriptor)).findFirst(); 42 | } 43 | 44 | private Predicate matchingInfo(String methodName, String descriptor) { 45 | return info -> 46 | Objects.equals(info.methodName, methodName) && Objects.equals(descriptor, info.descriptor); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /logback-turbomarker/src/main/java/com/tersesystems/logback/turbomarker/ContextAwareTurboMarker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.turbomarker; 12 | 13 | import static java.util.Objects.requireNonNull; 14 | 15 | import ch.qos.logback.classic.Level; 16 | import ch.qos.logback.classic.Logger; 17 | import ch.qos.logback.core.spi.FilterReply; 18 | import com.tersesystems.logback.classic.TurboFilterDecider; 19 | import org.slf4j.Marker; 20 | 21 | /** 22 | * This class passes through a custom application context and a matcher, which makes the ultimate 23 | * decision. 24 | * 25 | * @param the context of the predicate marker. 26 | */ 27 | public class ContextAwareTurboMarker extends TurboMarker implements TurboFilterDecider { 28 | 29 | private final C context; 30 | private final ContextAwareTurboFilterDecider contextAwareDecider; 31 | 32 | public ContextAwareTurboMarker( 33 | String name, C context, ContextAwareTurboFilterDecider decider) { 34 | super(name); 35 | this.context = requireNonNull(context); 36 | this.contextAwareDecider = requireNonNull(decider); 37 | } 38 | 39 | ContextAwareTurboFilterDecider getContextAwareDecider() { 40 | return contextAwareDecider; 41 | } 42 | 43 | C getContext() { 44 | return context; 45 | } 46 | 47 | @Override 48 | public FilterReply decide( 49 | Marker rootMarker, Logger logger, Level level, String format, Object[] params, Throwable t) { 50 | return contextAwareDecider.decide(this, context, rootMarker, logger, level, format, params, t); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /logback-censor/src/test/resources/test4.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | hunter4 23 | [CENSOR4] 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | { 33 | "custom_constant": "123", 34 | "tags": ["one", "two"], 35 | "logger": "%logger", 36 | "level": "%level", 37 | "thread": "%thread", 38 | "message": "%censor(%message){json-censor}" 39 | } 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /logback-honeycomb-client/src/main/java/com/tersesystems/logback/honeycomb/client/HoneycombResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.honeycomb.client; 12 | 13 | public class HoneycombResponse { 14 | 15 | private final String reason; 16 | private final int status; 17 | 18 | public HoneycombResponse(int status, String reason) { 19 | this.status = status; 20 | this.reason = reason; 21 | } 22 | 23 | public int getStatus() { 24 | return status; 25 | } 26 | 27 | public String getReason() { 28 | return reason; 29 | } 30 | 31 | public boolean isSuccess() { 32 | return (getStatus() == 200 || getStatus() == 202); 33 | } 34 | 35 | public boolean isInvalidKey() { 36 | return is400() && getReason().contains("credentials"); 37 | } 38 | 39 | public boolean isMalformed() { 40 | return is400() && getReason().contains("malformed"); 41 | } 42 | 43 | public boolean isTooLarge() { 44 | return is400() && getReason().contains("too large"); 45 | } 46 | 47 | public boolean isRateLimited() { 48 | return is429() && getReason().contains("rate limiting"); 49 | } 50 | 51 | public boolean isBlacklisted() { 52 | return is429() && getReason().contains("blacklisted"); 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return String.format("HoneyCombResponse(code = %s, text = %s)", getStatus(), getReason()); 58 | } 59 | 60 | private boolean is400() { 61 | return getStatus() == 400; 62 | } 63 | 64 | private boolean is429() { 65 | return getStatus() == 429; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /logback-classic/src/main/java/com/tersesystems/logback/classic/functional/GetAppenderFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic.functional; 12 | 13 | import static java.util.Objects.requireNonNull; 14 | 15 | import ch.qos.logback.classic.Logger; 16 | import ch.qos.logback.classic.LoggerContext; 17 | import ch.qos.logback.classic.spi.ILoggingEvent; 18 | import ch.qos.logback.core.Appender; 19 | import com.tersesystems.logback.classic.Utils; 20 | import java.util.Optional; 21 | import java.util.function.Function; 22 | 23 | public class GetAppenderFunction> 24 | implements Function> { 25 | 26 | private final Logger rootLogger; 27 | 28 | public GetAppenderFunction(Logger rootLogger) { 29 | this.rootLogger = rootLogger; 30 | } 31 | 32 | @SuppressWarnings("unchecked") 33 | @Override 34 | public Optional apply(String appenderName) { 35 | Appender appender = rootLogger.getAppender(requireNonNull(appenderName)); 36 | try { 37 | return Optional.ofNullable((A) appender); 38 | } catch (ClassCastException e) { 39 | return Optional.empty(); 40 | } 41 | } 42 | 43 | public static > GetAppenderFunction create() { 44 | return create(Utils.defaultContext()); 45 | } 46 | 47 | public static > GetAppenderFunction create( 48 | LoggerContext context) { 49 | Logger logger = RootLoggerSupplier.create(context).get(); 50 | return new GetAppenderFunction<>(logger); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /logback-core/src/test/java/com/tersesystems/logback/core/CompositeAppenderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.core; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import ch.qos.logback.classic.Logger; 16 | import ch.qos.logback.classic.LoggerContext; 17 | import ch.qos.logback.classic.joran.JoranConfigurator; 18 | import ch.qos.logback.classic.spi.ILoggingEvent; 19 | import ch.qos.logback.core.joran.spi.JoranException; 20 | import ch.qos.logback.core.read.ListAppender; 21 | import java.net.URL; 22 | import org.junit.Test; 23 | 24 | public class CompositeAppenderTest { 25 | 26 | @Test 27 | public void testSimpleAppender() throws JoranException { 28 | LoggerContext context = new LoggerContext(); 29 | URL resource = getClass().getResource("/logback-with-composite-appender.xml"); 30 | JoranConfigurator configurator = new JoranConfigurator(); 31 | configurator.setContext(context); 32 | configurator.doConfigure(resource); 33 | 34 | ch.qos.logback.classic.Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME); 35 | CompositeAppender composite = 36 | (CompositeAppender) logger.getAppender("CONSOLE_AND_FILE"); 37 | ListAppender file = (ListAppender) composite.getAppender("FILE"); 38 | ListAppender console = 39 | (ListAppender) composite.getAppender("CONSOLE"); 40 | 41 | logger.info("hello world"); 42 | assertThat(file.list.get(0).getMessage()).isEqualTo("hello world"); 43 | assertThat(console.list.get(0).getMessage()).isEqualTo("hello world"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /logback-tracing/src/main/java/com/tersesystems/logback/tracing/SpanMarkerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.tracing; 12 | 13 | import com.tersesystems.logback.classic.StartTimeMarker; 14 | import net.logstash.logback.marker.LogstashMarker; 15 | import net.logstash.logback.marker.Markers; 16 | 17 | /** 18 | * This is a marker factory that adds several logstash markers to create a span in Honeycomb format. 19 | */ 20 | public class SpanMarkerFactory { 21 | 22 | // Java API 23 | public LogstashMarker create(SpanInfo spanInfo) { 24 | StartTimeMarker startTime = new StartTimeMarker(spanInfo.startTime()); 25 | LogstashMarker[] markers = generateMarkers(spanInfo); 26 | return Markers.aggregate(markers).and(startTime); 27 | } 28 | 29 | // Scala API 30 | public LogstashMarker apply(SpanInfo spanInfo) { 31 | return create(spanInfo); 32 | } 33 | 34 | protected LogstashMarker[] generateMarkers(SpanInfo spanInfo) { 35 | LogstashMarker nameMarker = Markers.append("name", spanInfo.name()); 36 | LogstashMarker spanIdMarker = Markers.append("trace.span_id", spanInfo.spanId()); 37 | LogstashMarker parentIdMarker = Markers.append("trace.parent_id", spanInfo.parentId()); 38 | LogstashMarker traceIdMarker = Markers.append("trace.trace_id", spanInfo.traceId()); 39 | LogstashMarker serviceNameMarker = Markers.append("service_name", spanInfo.serviceName()); 40 | LogstashMarker durationMs = Markers.append("duration_ms", spanInfo.duration().toMillis()); 41 | LogstashMarker[] markers = { 42 | nameMarker, spanIdMarker, parentIdMarker, traceIdMarker, serviceNameMarker, durationMs 43 | }; 44 | return markers; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /logback-exception-mapping-providers/src/test/java/com/tersesystems/logback/exceptionmapping/json/TypesafeConfigMappingsActionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.exceptionmapping.json; 12 | 13 | import static com.tersesystems.logback.exceptionmapping.Constants.DEFAULT_MAPPINGS_KEY; 14 | import static com.tersesystems.logback.exceptionmapping.Constants.REGISTRY_BAG; 15 | import static java.util.Objects.requireNonNull; 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | 18 | import ch.qos.logback.classic.LoggerContext; 19 | import ch.qos.logback.classic.joran.JoranConfigurator; 20 | import ch.qos.logback.core.joran.spi.JoranException; 21 | import com.tersesystems.logback.exceptionmapping.ExceptionMappingRegistry; 22 | import java.util.Map; 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | 26 | public class TypesafeConfigMappingsActionTest { 27 | 28 | private final JoranConfigurator jc = new JoranConfigurator(); 29 | private final LoggerContext loggerContext = new LoggerContext(); 30 | 31 | @Before 32 | public void setUp() { 33 | jc.setContext(loggerContext); 34 | } 35 | 36 | @Test 37 | public void testConfig() throws JoranException { 38 | jc.doConfigure( 39 | requireNonNull( 40 | this.getClass().getClassLoader().getResource("logback-with-exception-mapping.xml"))); 41 | 42 | Map registryMap = 43 | (Map) loggerContext.getObject(REGISTRY_BAG); 44 | ExceptionMappingRegistry registry = registryMap.get(DEFAULT_MAPPINGS_KEY); 45 | assertThat( 46 | registry.contains("com.tersesystems.logback.exceptionmapping.json.MySpecialException")) 47 | .isTrue(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /logback-bytebuddy/src/main/java/com/tersesystems/logback/bytebuddy/impl/SafeArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.bytebuddy.impl; 12 | 13 | import java.security.cert.X509Certificate; 14 | import java.util.*; 15 | import java.util.stream.Collectors; 16 | import java.util.stream.Stream; 17 | 18 | public class SafeArguments { 19 | public List apply(Object[] allArguments) { 20 | return Arrays.stream(allArguments).map(this::apply).collect(Collectors.toList()); 21 | } 22 | 23 | public String apply(Object returnValue) { 24 | try { 25 | if (returnValue instanceof Collection) { 26 | return parseCollection((Collection) returnValue); 27 | } 28 | 29 | if (returnValue instanceof Object[]) { 30 | return parseArray((Object[]) returnValue); 31 | } 32 | 33 | if (returnValue instanceof X509Certificate) { 34 | return parseCertificate((X509Certificate) returnValue); 35 | } 36 | 37 | return Objects.toString(returnValue); 38 | } catch (Exception e) { 39 | return "Exception rendering safeArguments: " + e.toString(); 40 | } 41 | } 42 | 43 | private String parseCertificate(X509Certificate cert) { 44 | String s = cert.getSerialNumber().toString(16); 45 | String sub = cert.getSubjectDN().getName(); 46 | return "X509Certificate(serialNumber = " + s + ", subject = " + sub + ")"; 47 | } 48 | 49 | private String parseArray(Object[] returnValue) { 50 | return parseStream(Arrays.stream(returnValue)); 51 | } 52 | 53 | private String parseCollection(Collection coll) { 54 | return parseStream(coll.stream()); 55 | } 56 | 57 | private String parseStream(Stream stream) { 58 | return stream.map(this::apply).collect(Collectors.joining(",")); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /logback-audio/src/main/java/com/tersesystems/logback/audio/SimplePlayer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.audio; 12 | 13 | import static javax.sound.sampled.AudioSystem.getAudioInputStream; 14 | 15 | import java.io.IOException; 16 | import java.io.InputStream; 17 | import java.net.URL; 18 | import java.nio.file.Path; 19 | import java.util.function.Supplier; 20 | import javax.sound.sampled.AudioInputStream; 21 | import javax.sound.sampled.UnsupportedAudioFileException; 22 | 23 | public class SimplePlayer implements PlayMethods, Player { 24 | 25 | private final Supplier supplier; 26 | 27 | protected SimplePlayer(Supplier supplier) { 28 | this.supplier = supplier; 29 | } 30 | 31 | public static Player fromURL(URL url) { 32 | return new SimplePlayer( 33 | () -> { 34 | try { 35 | return getAudioInputStream(url); 36 | } catch (UnsupportedAudioFileException | IOException e) { 37 | throw new PlayerException(e); 38 | } 39 | }); 40 | } 41 | 42 | public static Player fromPath(Path path) { 43 | return new SimplePlayer( 44 | () -> { 45 | try { 46 | return getAudioInputStream(path.toFile()); 47 | } catch (UnsupportedAudioFileException | IOException e) { 48 | throw new PlayerException(e); 49 | } 50 | }); 51 | } 52 | 53 | public static Player fromInputStream(InputStream inputStream) { 54 | return new SimplePlayer( 55 | () -> { 56 | try { 57 | return getAudioInputStream(inputStream); 58 | } catch (UnsupportedAudioFileException | IOException e) { 59 | throw new PlayerException(e); 60 | } 61 | }); 62 | } 63 | 64 | @Override 65 | public void play() { 66 | play(supplier); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /logback-uniqueid-appender/src/test/java/com/tersesystems/logback/uniqueid/UniqueIdAppenderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.uniqueid; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import ch.qos.logback.classic.Logger; 16 | import ch.qos.logback.classic.LoggerContext; 17 | import ch.qos.logback.classic.joran.JoranConfigurator; 18 | import ch.qos.logback.classic.spi.ILoggingEvent; 19 | import ch.qos.logback.core.joran.spi.JoranException; 20 | import ch.qos.logback.core.read.ListAppender; 21 | import com.tersesystems.logback.core.ComponentContainer; 22 | import com.tersesystems.logback.core.DecoratingAppender; 23 | import java.net.URL; 24 | import org.junit.Test; 25 | 26 | public class UniqueIdAppenderTest { 27 | 28 | @Test 29 | public void testUniqueIdEventAppender() throws JoranException { 30 | LoggerContext context = new LoggerContext(); 31 | URL resource = getClass().getResource("/logback-with-uniqueid-appender.xml"); 32 | JoranConfigurator configurator = new JoranConfigurator(); 33 | configurator.setContext(context); 34 | configurator.doConfigure(resource); 35 | 36 | ch.qos.logback.classic.Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME); 37 | 38 | logger.info("hello world"); 39 | DecoratingAppender appender = 40 | (DecoratingAppender) 41 | logger.getAppender("DECORATE_WITH_UNIQUEID"); 42 | 43 | ListAppender listAppender = 44 | (ListAppender) appender.getAppender("LIST"); 45 | ILoggingEvent event = listAppender.list.get(0); 46 | ComponentContainer container = (ComponentContainer) event; 47 | UniqueIdProvider idComponent = container.getComponent(UniqueIdProvider.class); 48 | assertThat(idComponent.uniqueId()).isNotBlank(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /logback-classic/src/test/java/com/tersesystems/logback/classic/UtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: CC0-1.0 3 | * 4 | * Copyright 2018-2020 Will Sargent. 5 | * 6 | * Licensed under the CC0 Public Domain Dedication; 7 | * You may obtain a copy of the License at 8 | * 9 | * http://creativecommons.org/publicdomain/zero/1.0/ 10 | */ 11 | package com.tersesystems.logback.classic; 12 | 13 | import static org.assertj.core.api.Assertions.assertThat; 14 | 15 | import ch.qos.logback.classic.Level; 16 | import ch.qos.logback.classic.Logger; 17 | import ch.qos.logback.classic.LoggerContext; 18 | import ch.qos.logback.classic.turbo.MDCFilter; 19 | import ch.qos.logback.classic.turbo.TurboFilter; 20 | import ch.qos.logback.core.spi.FilterReply; 21 | import org.junit.jupiter.api.Test; 22 | import org.slf4j.Marker; 23 | 24 | public class UtilsTest { 25 | 26 | static class FancyTurboFilter extends TurboFilter { 27 | @Override 28 | public FilterReply decide( 29 | Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) { 30 | return null; 31 | } 32 | } 33 | 34 | @Test 35 | public void testTurboFilterMatchingType() { 36 | LoggerContext loggerContext = new LoggerContext(); 37 | FancyTurboFilter fancyTurboFilter = new FancyTurboFilter(); 38 | fancyTurboFilter.setName("fancyTurboFilter"); 39 | fancyTurboFilter.setContext(loggerContext); 40 | loggerContext.addTurboFilter(fancyTurboFilter); 41 | 42 | Utils utils = Utils.create(loggerContext); 43 | assertThat(utils.getTurboFilter(FancyTurboFilter.class, "fancyTurboFilter")).isNotEmpty(); 44 | } 45 | 46 | @Test 47 | public void testTurboFilterNonMatchingType() { 48 | LoggerContext loggerContext = new LoggerContext(); 49 | FancyTurboFilter fancyTurboFilter = new FancyTurboFilter(); 50 | fancyTurboFilter.setName("fancyTurboFilter"); 51 | fancyTurboFilter.setContext(loggerContext); 52 | loggerContext.addTurboFilter(fancyTurboFilter); 53 | 54 | Utils utils = Utils.create(loggerContext); 55 | assertThat(utils.getTurboFilter(MDCFilter.class, "fancyTurboFilter")).isEmpty(); 56 | } 57 | } 58 | --------------------------------------------------------------------------------