@@ -69,7 +69,29 @@ export class LogViewerProvider implements vscode.TreeDataProvider<LogFile>, vsco
6969 private getLogFileLines ( filePath : string ) : LogFile [ ] {
7070 const fileContent = fs . readFileSync ( filePath , 'utf-8' ) ;
7171 const lines = fileContent . split ( '\n' ) ;
72- return lines . map ( ( line , index ) => new LogFile ( `Line ${ index + 1 } : ${ line } ` , vscode . TreeItemCollapsibleState . None ) ) ;
72+ const groupedLines = this . groupLogEntries ( lines ) ;
73+ return groupedLines ;
74+ }
75+
76+ private groupLogEntries ( lines : string [ ] ) : LogFile [ ] {
77+ const grouped : { [ key : string ] : string [ ] } = { ERROR : [ ] , WARN : [ ] , INFO : [ ] } ;
78+ lines . forEach ( line => {
79+ if ( line . includes ( '.ERROR:' ) ) {
80+ grouped . ERROR . push ( line ) ;
81+ } else if ( line . includes ( '.WARN:' ) ) {
82+ grouped . WARN . push ( line ) ;
83+ } else if ( line . includes ( '.INFO:' ) ) {
84+ grouped . INFO . push ( line ) ;
85+ }
86+ } ) ;
87+
88+ const summary = [
89+ new LogFile ( `ERROR: ${ grouped . ERROR . length } entries` , vscode . TreeItemCollapsibleState . Collapsed , undefined , grouped . ERROR . map ( ( line , index ) => new LogFile ( `Line ${ index + 1 } : ${ line } ` , vscode . TreeItemCollapsibleState . None ) ) ) ,
90+ new LogFile ( `WARN: ${ grouped . WARN . length } entries` , vscode . TreeItemCollapsibleState . Collapsed , undefined , grouped . WARN . map ( ( line , index ) => new LogFile ( `Line ${ index + 1 } : ${ line } ` , vscode . TreeItemCollapsibleState . None ) ) ) ,
91+ new LogFile ( `INFO: ${ grouped . INFO . length } entries` , vscode . TreeItemCollapsibleState . Collapsed , undefined , grouped . INFO . map ( ( line , index ) => new LogFile ( `Line ${ index + 1 } : ${ line } ` , vscode . TreeItemCollapsibleState . None ) ) )
92+ ] ;
93+
94+ return summary ;
7395 }
7496
7597 getLogFilesWithoutUpdatingBadge ( dir : string ) : LogFile [ ] {
@@ -116,19 +138,16 @@ export class LogFile extends vscode.TreeItem {
116138 constructor (
117139 public readonly label : string ,
118140 public readonly collapsibleState : vscode . TreeItemCollapsibleState ,
119- public readonly command ?: vscode . Command
141+ public readonly command ?: vscode . Command ,
142+ public children ?: LogFile [ ]
120143 ) {
121144 super ( label , collapsibleState ) ;
122145 this . description = this . label . match ( / \( \d + \) / ) ?. [ 0 ] || '' ;
123146 this . label = this . label . replace ( / \( \d + \) / , '' ) . trim ( ) ;
124147 }
125148
126- iconPath = {
127- light : path . join ( __filename , '..' , '..' , 'resources' , 'light' , 'log.svg' ) ,
128- dark : path . join ( __filename , '..' , '..' , 'resources' , 'dark' , 'log.svg' )
129- } ;
149+ iconPath = new vscode . ThemeIcon ( 'file' ) ;
130150
131151 contextValue = 'logFile' ;
132152 description = '' ;
133- children : LogFile [ ] | undefined ;
134153}
0 commit comments