-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding "callerOf(Class<?>)" to LogSites to allow simpler APIs for log…
…ging utilities. This avoids people needing to expose "LogSite" as a parameter in logging helper classes and should allow most of the current ~350 call sites using it to be simplified. This is a retry of the previous change which accidentally broke anyone who was relying on being able to set an INVALID log site to suppress log site determination (that's apparently a thing in Android). RELNOTES=Adding "callerOf(Class<?>)" to LogSites. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=289240473
- Loading branch information
Showing
6 changed files
with
158 additions
and
10 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
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
52 changes: 52 additions & 0 deletions
52
api/src/test/java/com/google/common/flogger/LogSitesTest.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,52 @@ | ||
/* | ||
* Copyright (C) 2020 The Flogger Authors. | ||
* | ||
* 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.google.common.flogger; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public final class LogSitesTest { | ||
@Test | ||
public void testLogSite() { | ||
assertThat(LogSites.logSite().getMethodName()).isEqualTo("testLogSite"); | ||
} | ||
|
||
@Test | ||
public void testCallerOf() { | ||
assertThat(MyLogUtil.getCallerLogSite().getMethodName()).isEqualTo("testCallerOf"); | ||
assertThat(MyLogUtil.getCallerLogSiteWrapped().getMethodName()).isEqualTo("testCallerOf"); | ||
} | ||
|
||
@Test | ||
public void testCallerOf_notFound() { | ||
assertThat(LogSites.callerOf(String.class)).isEqualTo(LogSite.INVALID); | ||
} | ||
|
||
private static class MyLogUtil { | ||
static LogSite getCallerLogSite() { | ||
return LogSites.callerOf(MyLogUtil.class); | ||
} | ||
|
||
static LogSite getCallerLogSiteWrapped() { | ||
return getCallerLogSite(); | ||
} | ||
} | ||
} |
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