Repository: incubator-reef Updated Branches: refs/heads/master 4f5bb42c5 -> eb7165a8a
[REEF-562] Add Logger.IsLoggable(Level) This addressed the issue by * Adding an IsLoggable call to Logger. * Fix typo in CustomLevel member. JIRA: [REEF-562](https://issues.apache.org/jira/browse/REEF-562) Pull Request: This closes #362 Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/eb7165a8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/eb7165a8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/eb7165a8 Branch: refs/heads/master Commit: eb7165a8acd318ba29ebdf18b591c48cebe57b00 Parents: 4f5bb42 Author: Andrew Chung <[email protected]> Authored: Mon Aug 10 15:22:05 2015 -0700 Committer: Markus Weimer <[email protected]> Committed: Mon Aug 10 16:10:27 2015 -0700 ---------------------------------------------------------------------- .../Org.Apache.REEF.Utilities/Logging/Logger.cs | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/eb7165a8/lang/cs/Org.Apache.REEF.Utilities/Logging/Logger.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Utilities/Logging/Logger.cs b/lang/cs/Org.Apache.REEF.Utilities/Logging/Logger.cs index 624ad36..c011718 100644 --- a/lang/cs/Org.Apache.REEF.Utilities/Logging/Logger.cs +++ b/lang/cs/Org.Apache.REEF.Utilities/Logging/Logger.cs @@ -61,7 +61,7 @@ namespace Org.Apache.REEF.Utilities.Logging { _name = name; _traceSource = new TraceSource(_name, SourceLevels.All); - CustcomLevel = _customLevel; + CustomLevel = _customLevel; if (TraceListeners.Count == 0) { // before customized listener is added, we would need to log to console @@ -77,7 +77,7 @@ namespace Org.Apache.REEF.Utilities.Logging } } - public static Level CustcomLevel + public static Level CustomLevel { get { @@ -123,6 +123,14 @@ namespace Org.Apache.REEF.Utilities.Logging } /// <summary> + /// Determines whether or not the current log level will be logged by the logger. + /// </summary> + public bool IsLoggable(Level level) + { + return CustomLevel >= level; + } + + /// <summary> /// Log the message with the specified Log Level. /// /// If addtional arguments are passed, the message will be treated as @@ -134,7 +142,7 @@ namespace Org.Apache.REEF.Utilities.Logging /// <param name="args"></param> public void Log(Level level, string formatStr, params object[] args) { - if (CustcomLevel >= level) + if (CustomLevel >= level) { string msg = FormatMessage(formatStr, args); string logMessage = @@ -153,8 +161,9 @@ namespace Org.Apache.REEF.Utilities.Logging public void Log(Level level, string msg, Exception exception) { - string exceptionLog = string.Empty; - if (exception != null) + string exceptionLog; + + if (CustomLevel >= level && exception != null) { exceptionLog = string.Format( CultureInfo.InvariantCulture, @@ -163,6 +172,11 @@ namespace Org.Apache.REEF.Utilities.Logging exception.Message, exception.StackTrace); } + else + { + exceptionLog = string.Empty; + } + Log(level, msg + exceptionLog); }
