-
Notifications
You must be signed in to change notification settings - Fork 541
/
Copy pathLogger.cs
80 lines (72 loc) · 1.88 KB
/
Logger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.IO;
namespace Xamarin.Android.Tools.JavaDocToMdoc
{
public static class Logger
{
const string LogCategoryName = "JavadocToMDoc";
static TextWriter Output {
get { return Application.ProcessingContext.LoggingOutput; }
}
public static LoggingVerbosity Verbosity { get; set; } = LoggingVerbosity.Warning;
static bool ShouldLog (LoggingVerbosity toCheck)
{
return (int) toCheck <= (int) Verbosity;
}
static string LoggingVerbosityToLabel (LoggingVerbosity v)
{
switch (v) {
case LoggingVerbosity.Error: return "error ";
case LoggingVerbosity.Warning: return "warning ";
case LoggingVerbosity.Debug: return string.Empty;
default: throw new NotSupportedException ();
}
}
internal static void Log (LoggingVerbosity verbosity, int errorCode, string message)
{
if (!ShouldLog (verbosity))
return;
switch (verbosity) {
case LoggingVerbosity.Error:
case LoggingVerbosity.Warning:
Output.Write (LoggingVerbosityToLabel (verbosity));
break;
}
Output.Write (LogCategoryName);
switch (verbosity) {
case LoggingVerbosity.Error:
case LoggingVerbosity.Warning:
Output.Write (errorCode.ToString ("D04"));
break;
}
Output.Write (" : ");
Output.WriteLine (message);
}
internal static void Log (LoggingVerbosity verbosity, int errorCode, string format, params object [] args)
{
if (!ShouldLog (verbosity))
return;
switch (verbosity) {
case LoggingVerbosity.Error:
case LoggingVerbosity.Warning:
Output.Write (LoggingVerbosityToLabel (verbosity));
break;
}
Output.Write (LogCategoryName);
switch (verbosity) {
case LoggingVerbosity.Error:
case LoggingVerbosity.Warning:
Output.Write (errorCode.ToString ("D04"));
break;
}
Output.Write (" : ");
Output.WriteLine (format, args);
}
}
public enum LoggingVerbosity
{
Error,
Warning,
Debug,
}
}