Skip to content

Commit

Permalink
Implement the SafeLogger API (#566)
Browse files Browse the repository at this point in the history
Implement the SafeLogger API
  • Loading branch information
carterkozak authored Jul 21, 2021
1 parent 3b358bb commit d8f9b07
Show file tree
Hide file tree
Showing 16 changed files with 5,537 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .baseline/checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@

<!-- Generated code should not be subjected to checkstyle. -->
<suppress files="[/\\].*[/\\]generated.*[/\\]" checks="." />

<!-- Generated SafeLogger/SafeLoggerBridge should not be subjected to checkstyle. -->
<suppress files=".*SafeLogger.*" checks=".*" />
</suppressions>
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-566.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Implement the SafeLogger API
links:
- https://github.com/palantir/safe-logging/pull/566
16 changes: 16 additions & 0 deletions logger-generator/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
dependencies {
implementation 'org.slf4j:slf4j-api'
implementation project(':safe-logging')
implementation 'com.google.errorprone:error_prone_annotations'
implementation 'com.squareup:javapoet'
implementation 'com.palantir.goethe:goethe'
}

sourceCompatibility = 11

task generate(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'com.palantir.logsafe.logger.generator.LoggerGenerator'
}

tasks.check.dependsOn tasks.generate

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions logger-slf4j/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apply plugin: 'com.palantir.external-publish-jar'
apply plugin: 'com.palantir.revapi'

dependencies {
api project(':logger-spi')
implementation 'com.google.errorprone:error_prone_annotations'
implementation 'org.slf4j:slf4j-api'

compileOnly 'com.google.auto.service:auto-service-annotations'
annotationProcessor 'com.google.auto.service:auto-service'
}

sourceCompatibility = 11
// No great way to use a block comment for copyright statements
tasks.spotlessJavaCheck.enabled = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* (c) Copyright 2021 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.logsafe.logger.slf4j;

import com.google.auto.service.AutoService;
import com.palantir.logsafe.Safe;
import com.palantir.logsafe.logger.spi.SafeLoggerBridge;
import com.palantir.logsafe.logger.spi.SafeLoggerFactoryBridge;
import org.slf4j.LoggerFactory;

@AutoService(SafeLoggerFactoryBridge.class)
public final class Slf4JSafeLoggerFactoryBridge implements SafeLoggerFactoryBridge {

/** ServiceLoader requires a public no-arg constructor */
public Slf4JSafeLoggerFactoryBridge() {}

@Override
public int priority() {
// Default priority, negative values may be used
// to opt out and positive values are preferred.
return 0;
}

@Override
public SafeLoggerBridge get(@Safe Class<?> clazz) {
return new Slf4jSafeLoggerBridge(LoggerFactory.getLogger(clazz));
}

@Override
public SafeLoggerBridge get(@Safe String name) {
return new Slf4jSafeLoggerBridge(LoggerFactory.getLogger(name));
}
}
Loading

0 comments on commit d8f9b07

Please sign in to comment.