New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add writeSynchronicity flag to appender configuration #542
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
df573a0
feat: add support for write synchronicity config
minherz b898352
chore: set default value and remove debug output
minherz 24f4bf4
chore: remove async testing from samples
minherz 9b6e588
chore: change type of writeSynchronicity to enum
minherz File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
import com.google.cloud.logging.MonitoredResourceUtil; | ||
import com.google.cloud.logging.Payload; | ||
import com.google.cloud.logging.Severity; | ||
import com.google.cloud.logging.Synchronicity; | ||
import com.google.common.base.Strings; | ||
import com.google.common.collect.ImmutableList; | ||
import java.io.FileInputStream; | ||
|
@@ -63,8 +64,12 @@ | |
* <!-- Optional: defaults to "ERROR" --> | ||
* <flushLevel>WARNING</flushLevel> | ||
* | ||
* <!-- Optional: defaults to "ASYNC" --> | ||
* <writeSynchronicity>SYNC</writeSynchronicity> | ||
* | ||
* <!-- Optional: auto detects on App Engine Flex, Standard, GCE and GKE, defaults to "global". See <a | ||
* href="https://cloud.google.com/logging/docs/api/v2/resource-list">supported resource types</a> --> | ||
* href= | ||
* "https://cloud.google.com/logging/docs/api/v2/resource-list">supported resource types</a> --> | ||
* <resourceType></resourceType> | ||
* | ||
* <!-- Optional: defaults to the default credentials of the environment --> | ||
|
@@ -96,6 +101,7 @@ public class LoggingAppender extends UnsynchronizedAppenderBase<ILoggingEvent> { | |
private String log; | ||
private String resourceType; | ||
private String credentialsFile; | ||
private Synchronicity writeSyncFlag = Synchronicity.ASYNC; | ||
private final Set<String> enhancerClassNames = new HashSet<>(); | ||
private final Set<String> loggingEventEnhancerClassNames = new HashSet<>(); | ||
|
||
|
@@ -122,8 +128,9 @@ public void setLog(String log) { | |
/** | ||
* Sets the name of the monitored resource (Optional). | ||
* | ||
* <p>Must be a <a href="https://cloud.google.com/logging/docs/api/v2/resource-list">supported</a> | ||
* resource type. gae_app, gce_instance and container are auto-detected. | ||
* <p>Must be a <a href= | ||
* "https://cloud.google.com/logging/docs/api/v2/resource-list">supported</a> resource type. | ||
* gae_app, gce_instance and container are auto-detected. | ||
* | ||
* <p>Defaults to "global" | ||
* | ||
|
@@ -144,6 +151,19 @@ public void setCredentialsFile(String credentialsFile) { | |
this.credentialsFile = credentialsFile; | ||
} | ||
|
||
/** | ||
* Define synchronization mode for writing log entries. | ||
* | ||
* @param log flag | ||
*/ | ||
public void setWriteSynchronicity(String flag) { | ||
try { | ||
this.writeSyncFlag = Synchronicity.valueOf(flag); | ||
} catch (IllegalArgumentException e) { | ||
this.writeSyncFlag = Synchronicity.ASYNC; // use default value | ||
} | ||
} | ||
|
||
/** Add extra labels using classes that implement {@link LoggingEnhancer}. */ | ||
public void addEnhancer(String enhancerClassName) { | ||
this.enhancerClassNames.add(enhancerClassName); | ||
|
@@ -161,6 +181,12 @@ String getLogName() { | |
return (log != null) ? log : "java.log"; | ||
} | ||
|
||
public String getWriteSynchronicity() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not returning the enum? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be symetric with |
||
return (this.writeSyncFlag != null) | ||
? this.writeSyncFlag.toString() | ||
: Synchronicity.ASYNC.toString(); | ||
} | ||
|
||
MonitoredResource getMonitoredResource(String projectId) { | ||
return MonitoredResourceUtil.getResource(projectId, resourceType); | ||
} | ||
|
@@ -253,6 +279,7 @@ Logging getLogging() { | |
synchronized (this) { | ||
if (logging == null) { | ||
logging = getLoggingOptions().getService(); | ||
logging.setWriteSynchronicity(writeSyncFlag); | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: should this be enum instead of string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter is a value of the enum. There is no simple way to define specific type for logback appender parameters in the configuration. The value is parsed and in a case of failure the fallback is to the default value (ASYNC).