This repository was archived by the owner on Dec 12, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +92
-3
lines changed
CodeGeneration.Roslyn.Tasks
CodeGeneration.Roslyn.Tool Expand file tree Collapse file tree 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()
9191 argBuilder . AppendLine ( this . generatedCompileItemsFilePath ) ;
9292
9393 argBuilder . AppendLine ( "--" ) ;
94- foreach ( var item in this . Compile )
94+ foreach ( var item in this . Compile )
9595 {
9696 argBuilder . AppendLine ( item . ItemSpec ) ;
9797 }
9898
9999 return argBuilder . ToString ( ) ;
100100 }
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+ }
101140 }
102141}
Original file line number Diff line number Diff line change @@ -53,8 +53,10 @@ static int Main(string[] args)
5353 {
5454 generator . Generate ( progress ) ;
5555 }
56- catch
56+ catch ( Exception e )
5757 {
58+ Logger . Log ( LogLevel . High , $ "{ e . GetType ( ) . Name } : { e . Message } ") ;
59+ Logger . Log ( LogLevel . High , e . ToString ( ) ) ;
5860 return 3 ;
5961 }
6062
@@ -65,7 +67,7 @@ static int Main(string[] args)
6567
6668 foreach ( var file in generator . GeneratedFiles )
6769 {
68- Console . WriteLine ( file ) ;
70+ Logger . Log ( LogLevel . Normal , file ) ;
6971 }
7072
7173 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+ }
You can’t perform that action at this time.
0 commit comments