-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple log4j and logback example
- Loading branch information
1 parent
d16e476
commit 3e6f8d9
Showing
22 changed files
with
171 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormat | ||
import io.freefair.gradle.plugins.lombok.tasks.GenerateLombokConfig | ||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL | ||
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED | ||
import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED | ||
|
@@ -13,6 +15,7 @@ plugins { | |
`maven-publish` | ||
checkstyle | ||
id("com.github.sherter.google-java-format") version Version.google_format_gradle_plugin | ||
id("io.freefair.lombok") version Version.lombok_gradle_plugin | ||
} | ||
|
||
subprojects { | ||
|
@@ -23,6 +26,7 @@ subprojects { | |
apply(plugin = "maven-publish") | ||
apply(plugin = "com.github.sherter.google-java-format") | ||
apply(plugin = "checkstyle") | ||
apply(plugin = "io.freefair.lombok") | ||
|
||
repositories { | ||
mavenCentral() | ||
|
@@ -34,12 +38,16 @@ subprojects { | |
} | ||
|
||
checkstyle { | ||
version = 8.31 | ||
version = Version.checkstyle_gradle_plugin.toDouble() | ||
isIgnoreFailures = false | ||
maxErrors = 0 | ||
maxWarnings = 0 | ||
} | ||
|
||
lombok { | ||
setVersion(Version.lombok) | ||
} | ||
|
||
publishing { | ||
publications { | ||
create<MavenPublication>("maven") { | ||
|
@@ -63,7 +71,7 @@ subprojects { | |
id.set("carl") | ||
name.set("Carl-Philipp Harmant") | ||
email.set("[email protected]") | ||
organization.set("Slalom Build") | ||
organization.set("Slalom LLC") | ||
organizationUrl.set("https://www.slalombuild.com") | ||
} | ||
} | ||
|
@@ -94,6 +102,11 @@ subprojects { | |
} | ||
|
||
tasks.withType<Checkstyle> { | ||
dependsOn("googleJavaFormat") | ||
val googleJavaFormatTask = tasks.withType<GoogleJavaFormat>() | ||
dependsOn(googleJavaFormatTask) | ||
} | ||
} | ||
|
||
tasks.withType<GenerateLombokConfig> { | ||
enabled = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,10 @@ | ||
plugins { | ||
id("io.freefair.lombok") version Version.lombok_gradle_plugin | ||
} | ||
|
||
description = "Compliance Log4j2 library" | ||
|
||
dependencies { | ||
implementation(platform("org.apache.logging.log4j:log4j-bom:${Version.log4j2}")) | ||
api(platform("org.apache.logging.log4j:log4j-bom:${Version.log4j2}")) | ||
api(project(":compliance-logging-common")) | ||
|
||
implementation(group = "org.apache.logging.log4j", name = "log4j-api") | ||
implementation(group = "org.apache.logging.log4j", name = "log4j-core") | ||
api(group = "org.apache.logging.log4j", name = "log4j-api") | ||
api(group = "org.apache.logging.log4j", name = "log4j-core") | ||
|
||
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter") | ||
} |
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
...ance-logging-log4j2/src/main/java/com/slalom/logging/compliance/log4j2/mask/MaskType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.slalom.logging.compliance.log4j2.mask; | ||
|
||
import static com.slalom.logging.compliance.common.MaskType.JSON_MARKER_NAME; | ||
import static com.slalom.logging.compliance.common.MaskType.LOMBOK_MARKER_NAME; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.logging.log4j.Marker; | ||
import org.apache.logging.log4j.MarkerManager; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class MaskType { | ||
public static Marker JSON = MarkerManager.getMarker(JSON_MARKER_NAME); | ||
public static Marker LOMBOK = MarkerManager.getMarker(LOMBOK_MARKER_NAME); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
plugins { | ||
id("io.freefair.lombok") version Version.lombok_gradle_plugin | ||
} | ||
|
||
description = "Compliance Logback library" | ||
|
||
dependencies { | ||
api(project(":compliance-logging-common")) | ||
implementation(group = "ch.qos.logback", name = "logback-core", version = Version.logback) | ||
implementation(group = "ch.qos.logback", name = "logback-classic", version = Version.logback) | ||
api(group = "ch.qos.logback", name = "logback-core", version = Version.logback) | ||
api(group = "ch.qos.logback", name = "logback-classic", version = Version.logback) | ||
|
||
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter") | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dependencies { | ||
implementation(project(":compliance-logging-log4j2")) | ||
implementation(group = "com.fasterxml.jackson.core", name = "jackson-databind", version = Version.jackson) | ||
} | ||
|
||
// Do not publish artifact | ||
project.tasks.publishMavenPublicationToMavenLocal.get().enabled = false |
36 changes: 36 additions & 0 deletions
36
...g4j2-example/src/main/java/com/slalom/logging/compliance/example/SimpleLog4j2Example.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.slalom.logging.compliance.example; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.slalom.logging.compliance.log4j2.mask.MaskType; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.ToString; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class SimpleLog4j2Example { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(SimpleLog4j2Example.class); | ||
|
||
public static void main(String[] args) throws JsonProcessingException { | ||
final User user = | ||
User.builder().login("mylogin").password("mypassword").ssn("123-123-1234").build(); | ||
LOGGER.info( | ||
"================================================================================="); | ||
LOGGER.info("No Marker: {}", user); | ||
LOGGER.info(MaskType.LOMBOK, "Marker Lombok: {}", user); | ||
LOGGER.info(MaskType.JSON, "Marker Json: {}", new ObjectMapper().writeValueAsString(user)); | ||
LOGGER.info( | ||
"================================================================================="); | ||
} | ||
|
||
@Data | ||
@ToString | ||
@Builder | ||
public static class User { | ||
private final String login; | ||
private final String password; | ||
private final String ssn; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/simple-log4j2-example/src/main/resources/log4j2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration tatus="WARN" packages="com.slalom.logging"> | ||
<Properties> | ||
<Property name="COMPLIANCE_FIELDS">password,ssn</Property> | ||
<Property name="CONSOLE_LOG_PATTERN">%d{HH:mm:ss} [%t] %-5level %logger{36} - %mm{${COMPLIANCE_FIELDS}}%n | ||
</Property> | ||
</Properties> | ||
<appenders> | ||
<Console name="Console" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="${sys:CONSOLE_LOG_PATTERN}"/> | ||
</Console> | ||
</appenders> | ||
<loggers> | ||
<root level="info"> | ||
<appender-ref ref="Console"/> | ||
</root> | ||
</loggers> | ||
</Configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dependencies { | ||
implementation(project(":compliance-logging-logback")) | ||
implementation(group = "com.fasterxml.jackson.core", name = "jackson-databind", version = Version.jackson) | ||
} | ||
|
||
// Do not publish artifact | ||
project.tasks.publishMavenPublicationToMavenLocal.get().enabled = false |
36 changes: 36 additions & 0 deletions
36
...ack-example/src/main/java/com/slalom/logging/compliance/example/SimpleLogbackExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.slalom.logging.compliance.example; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.slalom.logging.compliance.common.MaskType; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.ToString; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SimpleLogbackExample { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleLogbackExample.class); | ||
|
||
public static void main(String[] args) throws JsonProcessingException { | ||
final User user = | ||
User.builder().login("mylogin").password("mypassword").ssn("123-123-1234").build(); | ||
LOGGER.info( | ||
"================================================================================="); | ||
LOGGER.info("No Marker: {}", user); | ||
LOGGER.info(MaskType.LOMBOK, "Marker Lombok: {}", user); | ||
LOGGER.info(MaskType.JSON, "Marker Json: {}", new ObjectMapper().writeValueAsString(user)); | ||
LOGGER.info( | ||
"================================================================================="); | ||
} | ||
|
||
@Data | ||
@ToString | ||
@Builder | ||
public static class User { | ||
private final String login; | ||
private final String password; | ||
private final String ssn; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/simple-logback-example/src/main/resources/logback.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> | ||
<layout class="com.slalom.logging.compliance.logback.PatternMaskingLayout"> | ||
<fields>password,ssn</fields> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</layout> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters