3 files changed +92
-3
lines changed Original file line number Diff line number Diff line change @@ -91,12 +91,51 @@ protected override string GenerateResponseFileCommands()
91
91
argBuilder . AppendLine ( this . generatedCompileItemsFilePath ) ;
92
92
93
93
argBuilder . AppendLine ( "--" ) ;
94
- foreach ( var item in this . Compile )
94
+ foreach ( var item in this . Compile )
95
95
{
96
96
argBuilder . AppendLine ( item . ItemSpec ) ;
97
97
}
98
98
99
99
return argBuilder . ToString ( ) ;
100
100
}
101
+
102
+ protected override void LogEventsFromTextOutput ( string singleLine , MessageImportance messageImportance )
103
+ {
104
+ MessageImportance newImportance ;
105
+ if ( DidExtractPrefix ( "High" ) )
106
+ {
107
+ newImportance = MessageImportance . High ;
108
+ }
109
+ else if ( DidExtractPrefix ( "Normal" ) )
110
+ {
111
+ newImportance = MessageImportance . Normal ;
112
+ }
113
+ else if ( DidExtractPrefix ( "Low" ) )
114
+ {
115
+ newImportance = MessageImportance . Low ;
116
+ }
117
+ else
118
+ {
119
+ newImportance = messageImportance ;
120
+ }
121
+
122
+ if ( newImportance < messageImportance )
123
+ {
124
+ messageImportance = newImportance ; // Lower value => higher importance
125
+ }
126
+
127
+ base . LogEventsFromTextOutput ( singleLine , messageImportance ) ;
128
+
129
+ bool DidExtractPrefix ( string importanceString )
130
+ {
131
+ var prefix = $ "::{ importanceString } ::";
132
+ if ( singleLine . StartsWith ( prefix ) )
133
+ {
134
+ singleLine = singleLine . Substring ( prefix . Length ) ;
135
+ return true ;
136
+ }
137
+ return false ;
138
+ }
139
+ }
101
140
}
102
141
}
Original file line number Diff line number Diff line change @@ -53,8 +53,10 @@ static int Main(string[] args)
53
53
{
54
54
generator . Generate ( progress ) ;
55
55
}
56
- catch
56
+ catch ( Exception e )
57
57
{
58
+ Logger . Log ( LogLevel . High , $ "{ e . GetType ( ) . Name } : { e . Message } ") ;
59
+ Logger . Log ( LogLevel . High , e . ToString ( ) ) ;
58
60
return 3 ;
59
61
}
60
62
@@ -65,7 +67,7 @@ static int Main(string[] args)
65
67
66
68
foreach ( var file in generator . GeneratedFiles )
67
69
{
68
- Console . WriteLine ( file ) ;
70
+ Logger . Log ( LogLevel . Normal , file ) ;
69
71
}
70
72
71
73
return 0 ;
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Text ;
4
+
5
+ namespace CodeGeneration . Roslyn
6
+ {
7
+ public enum LogLevel
8
+ {
9
+ /// <summary>
10
+ /// High importance, appears in less verbose logs
11
+ /// </summary>
12
+ High = 0 ,
13
+
14
+ /// <summary>
15
+ /// Normal importance
16
+ /// </summary>
17
+ Normal = 1 ,
18
+
19
+ /// <summary>
20
+ /// Low importance, appears in more verbose logs
21
+ /// </summary>
22
+ Low = 2 ,
23
+ }
24
+ public static class Logger
25
+ {
26
+ public static void Log ( LogLevel logLevel , string message )
27
+ {
28
+ // Prefix every Line with loglevel
29
+ var begin = 0 ;
30
+ var end = message . IndexOf ( '\n ' ) ;
31
+ bool foundR = end > 0 && message [ end - 1 ] == '\r ' ;
32
+ if ( foundR )
33
+ end -- ;
34
+ while ( end != - 1 )
35
+ {
36
+ Print ( message . Substring ( begin , end - begin ) ) ;
37
+ begin = end + ( foundR ? 2 : 1 ) ;
38
+ end = message . IndexOf ( '\n ' , begin ) ;
39
+ foundR = end > 0 && message [ end - 1 ] == '\r ' ;
40
+ if ( foundR )
41
+ end -- ;
42
+ }
43
+ Print ( message . Substring ( begin , message . Length - begin ) ) ;
44
+
45
+ void Print ( string toPrint ) => Console . WriteLine ( $ "::{ logLevel } ::{ toPrint } ") ;
46
+ }
47
+ }
48
+ }
0 commit comments