Skip to content

Commit

Permalink
Merge branch 'dev' into shahzaibj/msal-issue-1864-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzaibj authored Jan 26, 2024
2 parents fb1e99a + 652bbfb commit 897af40
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ V.Next
- [MINOR] Add PreferredAuthMethod to interactive token flow (#2245)
- [MINOR] Implement updates of the native auth web API (#2261)
- [MINOR] Update ResetPasswordPollCompletion related command, results, and responses to support signing in a user after a successful password reset. (#2281)
- [MINOR] Added support for setting no log level (#2282)

V.17.0.0
---------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public class Logger {
* Enum class for LogLevel that the sdk recognizes.
*/
public enum LogLevel {
/**
* Log level to disable logging.
*/
NO_LOG,
/**
* Error level logging.
*/
Expand All @@ -71,6 +75,8 @@ private com.microsoft.identity.common.java.logging.Logger.LogLevel convertToJava
return com.microsoft.identity.common.java.logging.Logger.LogLevel.WARN;
case ERROR:
return com.microsoft.identity.common.java.logging.Logger.LogLevel.ERROR;
case NO_LOG:
return com.microsoft.identity.common.java.logging.Logger.LogLevel.NO_LOG;
default:
return com.microsoft.identity.common.java.logging.Logger.LogLevel.VERBOSE;
}
Expand All @@ -85,6 +91,8 @@ private static LogLevel convertFromJavaLogLevel(
return WARN;
case ERROR:
return ERROR;
case NO_LOG:
return NO_LOG;
default:
return VERBOSE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public static void setPlatformString(String platformString) {
* Enum class for LogLevel that the sdk recognizes.
*/
public enum LogLevel {
/**
* No logs should be emitted.
*/
NO_LOG,
/**
* Error level logging.
*/
Expand All @@ -107,7 +111,7 @@ public enum LogLevel {
/**
* Undefined. Should be used in test only.
*/
UNDEFINED,
UNDEFINED
}

// Visible for testing
Expand Down Expand Up @@ -378,7 +382,7 @@ private static void log(final String tag,
final String message,
final Throwable throwable,
final boolean containsPII) {
if (logLevel.compareTo(sLogLevel) > 0 || (!sAllowPii && containsPII)) {
if ((sLogLevel == LogLevel.NO_LOG) || logLevel.compareTo(sLogLevel) > 0 || (!sAllowPii && containsPII)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,26 @@ public void execute() {
}, true);
}

@Test(timeout = TEST_TIME_OUT_IN_MILLISECONDS)
public void setLogLevelAsNoLog_LogWithVerbose() throws InterruptedException {
final boolean containsPII = false;

Logger.setLogLevel(Logger.LogLevel.NO_LOG);
testLogger(tag, Logger.LogLevel.VERBOSE, correlationId, message, containsPII, new IOperationToTest() {
@Override
public void execute() {
Logger.verbose(tag, correlationId, message);
}
}, true);

testLogger(tag, Logger.LogLevel.WARN, correlationId, message, containsPII, new IOperationToTest() {
@Override
public void execute() {
Logger.warn(tag, correlationId, message);
}
}, true);
}

@Test(timeout = TEST_TIME_OUT_IN_MILLISECONDS)
public void logPiiWhenDisabled() throws InterruptedException {
final Logger.LogLevel logLevel = Logger.LogLevel.VERBOSE;
Expand Down

0 comments on commit 897af40

Please sign in to comment.