-
Notifications
You must be signed in to change notification settings - Fork 15
Add replay-safe logging #295
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
Open
bachuv
wants to merge
2
commits into
main
Choose a base branch
from
vabachu/replay-safe-logger-java
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
300 changes: 300 additions & 0 deletions
300
client/src/main/java/com/microsoft/durabletask/ReplaySafeLogger.java
This file contains hidden or 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,300 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| package com.microsoft.durabletask; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.ResourceBundle; | ||
| import java.util.function.BooleanSupplier; | ||
| import java.util.function.Supplier; | ||
| import java.util.logging.Filter; | ||
| import java.util.logging.Handler; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.LogRecord; | ||
| import java.util.logging.Logger; | ||
|
|
||
| final class ReplaySafeLogger extends Logger { | ||
| private final Logger delegate; | ||
| private final BooleanSupplier isReplaying; | ||
|
|
||
| ReplaySafeLogger(Logger delegate, BooleanSupplier isReplaying) { | ||
| super(Objects.requireNonNull(delegate, "delegate").getName(), null); | ||
| this.delegate = delegate; | ||
| this.isReplaying = Objects.requireNonNull(isReplaying, "isReplaying"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isLoggable(Level level) { | ||
| return this.delegate.isLoggable(level); | ||
| } | ||
|
|
||
| @Override | ||
| public void log(LogRecord record) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.log(record); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void log(Level level, String message) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.log(level, message); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void log(Level level, Supplier<String> messageSupplier) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.log(level, messageSupplier); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void log(Level level, String message, Object parameter) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.log(level, message, parameter); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void log(Level level, String message, Object[] parameters) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.log(level, message, parameters); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void log(Level level, String message, Throwable thrown) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.log(level, message, thrown); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void log(Level level, Throwable thrown, Supplier<String> messageSupplier) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.log(level, thrown, messageSupplier); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void logp( | ||
| Level level, | ||
| String sourceClass, | ||
| String sourceMethod, | ||
| String message) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.logp(level, sourceClass, sourceMethod, message); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void logp( | ||
| Level level, | ||
| String sourceClass, | ||
| String sourceMethod, | ||
| Supplier<String> messageSupplier) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.logp(level, sourceClass, sourceMethod, messageSupplier); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void logp( | ||
|
bachuv marked this conversation as resolved.
Dismissed
|
||
| Level level, | ||
| String sourceClass, | ||
| String sourceMethod, | ||
| String message, | ||
| Object parameter) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.logp(level, sourceClass, sourceMethod, message, parameter); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void logp( | ||
| Level level, | ||
| String sourceClass, | ||
| String sourceMethod, | ||
| String message, | ||
| Object[] parameters) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.logp(level, sourceClass, sourceMethod, message, parameters); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void logp( | ||
| Level level, | ||
| String sourceClass, | ||
| String sourceMethod, | ||
| String message, | ||
| Throwable thrown) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.logp(level, sourceClass, sourceMethod, message, thrown); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void logp( | ||
| Level level, | ||
| String sourceClass, | ||
| String sourceMethod, | ||
| Throwable thrown, | ||
| Supplier<String> messageSupplier) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.logp(level, sourceClass, sourceMethod, thrown, messageSupplier); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void logrb( | ||
| Level level, | ||
| String sourceClass, | ||
| String sourceMethod, | ||
| String bundleName, | ||
| String message) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.logrb(level, sourceClass, sourceMethod, bundleName, message); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void logrb( | ||
|
bachuv marked this conversation as resolved.
Dismissed
|
||
| Level level, | ||
| String sourceClass, | ||
| String sourceMethod, | ||
| String bundleName, | ||
| String message, | ||
| Object parameter) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.logrb(level, sourceClass, sourceMethod, bundleName, message, parameter); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void logrb( | ||
| Level level, | ||
| String sourceClass, | ||
| String sourceMethod, | ||
| String bundleName, | ||
| String message, | ||
| Object[] parameters) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.logrb(level, sourceClass, sourceMethod, bundleName, message, parameters); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void logrb( | ||
| Level level, | ||
| String sourceClass, | ||
| String sourceMethod, | ||
| ResourceBundle bundle, | ||
| String message, | ||
| Object... parameters) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.logrb(level, sourceClass, sourceMethod, bundle, message, parameters); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void logrb( | ||
| Level level, | ||
| String sourceClass, | ||
| String sourceMethod, | ||
| String bundleName, | ||
| String message, | ||
| Throwable thrown) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.logrb(level, sourceClass, sourceMethod, bundleName, message, thrown); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void logrb( | ||
| Level level, | ||
| String sourceClass, | ||
| String sourceMethod, | ||
| ResourceBundle bundle, | ||
| String message, | ||
| Throwable thrown) { | ||
| if (!this.isReplaying.getAsBoolean()) { | ||
| this.delegate.logrb(level, sourceClass, sourceMethod, bundle, message, thrown); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return this.delegate.getName(); | ||
| } | ||
|
|
||
| @Override | ||
| public ResourceBundle getResourceBundle() { | ||
| return this.delegate.getResourceBundle(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getResourceBundleName() { | ||
| return this.delegate.getResourceBundleName(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setResourceBundle(ResourceBundle bundle) { | ||
| this.delegate.setResourceBundle(bundle); | ||
| } | ||
|
|
||
| @Override | ||
| public Filter getFilter() { | ||
| return this.delegate.getFilter(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setFilter(Filter filter) { | ||
| this.delegate.setFilter(filter); | ||
| } | ||
|
|
||
| @Override | ||
| public Level getLevel() { | ||
| return this.delegate.getLevel(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setLevel(Level level) { | ||
| this.delegate.setLevel(level); | ||
| } | ||
|
|
||
| @Override | ||
| public Handler[] getHandlers() { | ||
| return this.delegate.getHandlers(); | ||
| } | ||
|
|
||
| @Override | ||
| public void addHandler(Handler handler) { | ||
| this.delegate.addHandler(handler); | ||
| } | ||
|
|
||
| @Override | ||
| public void removeHandler(Handler handler) { | ||
| this.delegate.removeHandler(handler); | ||
| } | ||
|
|
||
| @Override | ||
| public Logger getParent() { | ||
| return this.delegate.getParent(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setParent(Logger parent) { | ||
| this.delegate.setParent(parent); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean getUseParentHandlers() { | ||
| return this.delegate.getUseParentHandlers(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setUseParentHandlers(boolean useParentHandlers) { | ||
| this.delegate.setUseParentHandlers(useParentHandlers); | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.