Repository: reef Updated Branches: refs/heads/master 5a8b518e3 -> 040a6b366
[REEF-1342] Allow to set log level per logger instance This change: * Adds a per-instance log level, that defaults to Level.Unset * If the per-instance log level is set, use that to determine if a message is logged; otherwise use the static log level. JIRA: [REEF-1342](https://issues.apache.org/jira/browse/REEF-1342) Pull request: This closes #965 Project: http://git-wip-us.apache.org/repos/asf/reef/repo Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/040a6b36 Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/040a6b36 Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/040a6b36 Branch: refs/heads/master Commit: 040a6b36666bafc31eb9c0881a5a37ec25deb086 Parents: 5a8b518 Author: Adrian Nicoara <[email protected]> Authored: Thu May 5 17:55:26 2016 -0700 Committer: Mariia Mykhailova <[email protected]> Committed: Mon May 9 12:04:10 2016 -0700 ---------------------------------------------------------------------- .../Runtime/Evaluator/Task/TaskRuntime.cs | 2 +- .../Org.Apache.REEF.Utilities/Logging/Level.cs | 6 ++++++ .../Org.Apache.REEF.Utilities/Logging/Logger.cs | 22 ++++++++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/reef/blob/040a6b36/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/TaskRuntime.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/TaskRuntime.cs b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/TaskRuntime.cs index 654706a..d56731c 100644 --- a/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/TaskRuntime.cs +++ b/lang/cs/Org.Apache.REEF.Common/Runtime/Evaluator/Task/TaskRuntime.cs @@ -104,7 +104,7 @@ namespace Org.Apache.REEF.Common.Runtime.Evaluator.Task const Level resultLogLevel = Level.Verbose; - if (Logger.CustomLevel >= resultLogLevel && result != null && result.Length > 0) + if (Logger.IsLoggable(resultLogLevel) && result != null && result.Length > 0) { Logger.Log(resultLogLevel, "Task running result:\r\n" + System.Text.Encoding.Default.GetString(result)); http://git-wip-us.apache.org/repos/asf/reef/blob/040a6b36/lang/cs/Org.Apache.REEF.Utilities/Logging/Level.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Utilities/Logging/Level.cs b/lang/cs/Org.Apache.REEF.Utilities/Logging/Level.cs index 5c32500..a444d9e 100644 --- a/lang/cs/Org.Apache.REEF.Utilities/Logging/Level.cs +++ b/lang/cs/Org.Apache.REEF.Utilities/Logging/Level.cs @@ -53,5 +53,11 @@ namespace Org.Apache.REEF.Utilities.Logging /// Output all debugging and tracing messages. /// </summary> Verbose = 6, + + /// <summary> + /// Used by the logger to initialize the instance log level field, + /// indicating that it has not been set by a user yet. + /// </summary> + Unset, } } http://git-wip-us.apache.org/repos/asf/reef/blob/040a6b36/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 ba8d8a0..88772be 100644 --- a/lang/cs/Org.Apache.REEF.Utilities/Logging/Logger.cs +++ b/lang/cs/Org.Apache.REEF.Utilities/Logging/Logger.cs @@ -49,6 +49,8 @@ namespace Org.Apache.REEF.Utilities.Logging private static Level _customLevel = Level.Info; + private Level _instanceLevel = Level.Unset; + private static List<TraceListener> _traceListeners; private readonly string _name; @@ -59,7 +61,6 @@ namespace Org.Apache.REEF.Utilities.Logging { _name = name; _traceSource = new TraceSource(_name, SourceLevels.All); - CustomLevel = _customLevel; if (TraceListeners.Count == 0) { // before customized listener is added, we would need to log to console @@ -88,6 +89,19 @@ namespace Org.Apache.REEF.Utilities.Logging } } + public Level InstanceLevel + { + get + { + return _instanceLevel; + } + + set + { + _instanceLevel = value; + } + } + public static List<TraceListener> TraceListeners { get @@ -125,7 +139,7 @@ namespace Org.Apache.REEF.Utilities.Logging /// </summary> public bool IsLoggable(Level level) { - return CustomLevel >= level; + return (InstanceLevel != Level.Unset ? InstanceLevel : CustomLevel) >= level; } /// <summary> @@ -140,7 +154,7 @@ namespace Org.Apache.REEF.Utilities.Logging /// <param name="args"></param> public void Log(Level level, string formatStr, params object[] args) { - if (CustomLevel >= level) + if (IsLoggable(level)) { string msg = FormatMessage(formatStr, args); string logMessage = @@ -161,7 +175,7 @@ namespace Org.Apache.REEF.Utilities.Logging { string exceptionLog; - if (CustomLevel >= level && exception != null) + if (IsLoggable(level) && exception != null) { exceptionLog = string.Format( CultureInfo.InvariantCulture,
