forked from nkast/MonoGame
-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathConsoleLogger.cs
76 lines (62 loc) · 2.48 KB
/
ConsoleLogger.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
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using Microsoft.Xna.Framework.Content.Pipeline;
namespace Microsoft.Xna.Framework.Content.Pipeline.Builder
{
internal class ConsoleLogger : ContentBuildLogger
{
private int indentCount = 0;
public virtual void Indent()
{
indentCount++;
}
public virtual void Unindent()
{
indentCount--;
}
protected string IndentString { get { return String.Empty.PadLeft(Math.Max(0, indentCount), '\t'); } }
public override void LogMessage(string message, params object[] messageArgs)
{
Console.WriteLine(IndentString + message, messageArgs);
}
public override void LogImportantMessage(string message, params object[] messageArgs)
{
// TODO: How do i make it high importance?
Console.WriteLine(IndentString + message, messageArgs);
}
public override void LogWarning(string helpLink, ContentIdentity contentIdentity, string message, params object[] messageArgs)
{
var warning = string.Empty;
if (contentIdentity != null && !string.IsNullOrEmpty(contentIdentity.SourceFilename))
{
warning = contentIdentity.SourceFilename;
if (!string.IsNullOrEmpty(contentIdentity.FragmentIdentifier))
warning += "(" + contentIdentity.FragmentIdentifier + ")";
else
warning += " ";
}
else
{
warning = GetCurrentFilename(contentIdentity);
warning += " ";
}
warning += ": warning ";
// extract errorCode from message
var match = System.Text.RegularExpressions.Regex.Match(message, @"([A-Z]+[0-9]+):(.+)");
if (match.Success || match.Groups.Count == 2)
{
warning += match.Groups[1].Value;
warning += " ";
message = match.Groups[2].Value;
}
warning += ": ";
if (messageArgs != null && messageArgs.Length != 0)
warning += string.Format(message, messageArgs);
else if (!string.IsNullOrEmpty(message))
warning += message;
Console.WriteLine(warning);
}
}
}