Skip to content

Commit

Permalink
fix: Fix a couple linter issues on my stderr update (#1061)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Creech <[email protected]>
  • Loading branch information
bpcreech and Ben Creech authored Sep 14, 2022
1 parent bfef3d1 commit fa1a18f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ public Boolean getAutoPopulateMetadata() {
* the Json format that can be parsed by the logging agent. If set to {@code false}, logs will be
* ingested to Cloud Logging by calling Logging API.
*
* <p>This method is mutually exclusive with {@link #setLogTarget()}.
* <p>This method is mutually exclusive with {@link #setLogTarget(LogTarget)}.
*
* @deprecated Use {@link #setLogTarget()}.
* @deprecated Use {@link #setLogTarget(LogTarget)}.
*/
@Deprecated
public void setRedirectToStdout(boolean value) {
Expand All @@ -475,7 +475,7 @@ public Boolean getRedirectToStdout() {
* to the corresponding stream in the Json format that can be parsed by the logging agent. If set
* to CLOUD_LOGGING, logs will be sent directly to the Google Cloud Logging API.
*
* <p>This method is mutually exclusive with {@link #setRedirectToStdout()}.
* <p>This method is mutually exclusive with {@link #setRedirectToStdout(boolean)}.
*/
public void setLogTarget(LogTarget value) {
this.logTarget = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.gson.JsonParser;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.logging.ErrorManager;
import java.util.logging.Filter;
import java.util.logging.Formatter;
Expand Down Expand Up @@ -398,14 +399,15 @@ public void testEnhancedLogEntry() {
handler.publish(newLogRecord(Level.FINEST, MESSAGE));
}

void validateJsonOutput(ByteArrayOutputStream bout) {
void validateJsonOutput(ByteArrayOutputStream bout) throws UnsupportedEncodingException {
final String expectedOutput =
"{\"severity\":\"INFO\",\"time\":\"1970-01-02T10:17:36.789Z\",\"logging.googleapis.com/labels\":{\"enhanced\":\"true\"},\"logging.googleapis.com/trace_sampled\":false,\"message\":\"message\"}";
assertEquals(JsonParser.parseString(expectedOutput), JsonParser.parseString(bout.toString()));
assertEquals(
JsonParser.parseString(expectedOutput), JsonParser.parseString(bout.toString("UTF-8")));
}

@Test
public void testEnhancedLogEntryPrintToStdout() {
public void testEnhancedLogEntryPrintToStdout() throws UnsupportedEncodingException {
outputStreamPatcher.patch();

replay(options, logging);
Expand All @@ -422,7 +424,7 @@ public void testEnhancedLogEntryPrintToStdout() {
}

@Test
public void testEnhancedLogEntryPrintToStderr() {
public void testEnhancedLogEntryPrintToStderr() throws UnsupportedEncodingException {
outputStreamPatcher.patch();

replay(options, logging);
Expand Down

0 comments on commit fa1a18f

Please sign in to comment.