-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-1652680: Add threshold for j.u.l. stderr stdout logging (#1988)
- Loading branch information
1 parent
6da3ca3
commit c9bf0e7
Showing
7 changed files
with
253 additions
and
17 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
40 changes: 40 additions & 0 deletions
40
src/main/java/net/snowflake/client/log/StdErrOutThresholdAwareConsoleHandler.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,40 @@ | ||
/* | ||
* Copyright (c) 2012-2019 Snowflake Computing Inc. All rights reserved. | ||
*/ | ||
package net.snowflake.client.log; | ||
|
||
import java.util.logging.ConsoleHandler; | ||
import java.util.logging.Level; | ||
import java.util.logging.LogRecord; | ||
import java.util.logging.SimpleFormatter; | ||
import java.util.logging.StreamHandler; | ||
|
||
class StdErrOutThresholdAwareConsoleHandler extends StreamHandler { | ||
private final ConsoleHandler stdErrConsoleHandler = new ConsoleHandler(); | ||
private final Level threshold; | ||
|
||
public StdErrOutThresholdAwareConsoleHandler(Level threshold) { | ||
super(System.out, new SimpleFormatter()); | ||
this.threshold = threshold; | ||
} | ||
|
||
@Override | ||
public void publish(LogRecord record) { | ||
if (record.getLevel().intValue() > threshold.intValue()) { | ||
stdErrConsoleHandler.publish(record); | ||
} else { | ||
super.publish(record); | ||
flush(); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
flush(); | ||
stdErrConsoleHandler.close(); | ||
} | ||
|
||
Level getThreshold() { | ||
return threshold; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/net/snowflake/client/log/UnknownJavaUtilLoggingLevelException.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,29 @@ | ||
/* | ||
* Copyright (c) 2012-2019 Snowflake Computing Inc. All rights reserved. | ||
*/ | ||
package net.snowflake.client.log; | ||
|
||
import java.util.logging.Level; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
class UnknownJavaUtilLoggingLevelException extends RuntimeException { | ||
private static final String AVAILABLE_LEVELS = | ||
Stream.of( | ||
Level.OFF, | ||
Level.SEVERE, | ||
Level.WARNING, | ||
Level.INFO, | ||
Level.CONFIG, | ||
Level.FINE, | ||
Level.FINER, | ||
Level.FINEST, | ||
Level.ALL) | ||
.map(Level::getName) | ||
.collect(Collectors.joining(", ")); | ||
|
||
UnknownJavaUtilLoggingLevelException(String threshold) { | ||
super( | ||
"Unknown java util logging level: " + threshold + ", expected one of: " + AVAILABLE_LEVELS); | ||
} | ||
} |
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