1
1
2
2
$peekBuf = $null
3
3
$currentLineNum = 1
4
- $logEntryNum = 1
4
+ $logEntryIndex = 0
5
5
6
6
function Parse-PsesLog {
7
7
param (
8
- # Specifies a path to one or more PSES EditorServices log files .
8
+ # Specifies a path to a PSES EditorServices log file .
9
9
[Parameter (Mandatory = $true , Position = 0 )]
10
10
[Alias (" PSPath" )]
11
11
[ValidateNotNullOrEmpty ()]
@@ -32,6 +32,10 @@ function Parse-PsesLog {
32
32
)
33
33
34
34
begin {
35
+ $script :peekBuf = $null
36
+ $script :currentLineNum = 1
37
+ $script :logEntryIndex = 0
38
+
35
39
# Example log entry start:
36
40
# 2018-11-24 12:26:58.302 [DIAGNOSTIC] tid:28 in 'ReadMessage' C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageReader.cs:114:
37
41
$logEntryRegex =
@@ -84,8 +88,8 @@ function Parse-PsesLog {
84
88
$line = nextLine
85
89
}
86
90
87
- if (! $HideProgress -and ($script :logEntryNum % 50 -eq 0 )) {
88
- Write-Progress " Processing log entry ${ script:logEntryNum } on line: ${ script:currentLineNum } "
91
+ if (! $HideProgress -and ($script :logEntryIndex % 50 -eq 0 )) {
92
+ Write-Progress " Processing log entry ${ script:logEntryIndex } on line: ${ script:currentLineNum } "
89
93
}
90
94
91
95
[string ]$timestampStr = $matches [" ts" ]
@@ -98,17 +102,17 @@ function Parse-PsesLog {
98
102
99
103
$message = parseMessage $method
100
104
101
- [PsesLogEntry ]::new($timestamp , $timestampStr , $logLevel , $threadId , $method , $file , $lineNumber ,
102
- $message.MessageType , $message.Message )
105
+ [PsesLogEntry ]::new($script :logEntryIndex , $ timestamp, $timestampStr , $logLevel , $threadId , $method ,
106
+ $file , $lineNumber , $ message.MessageType , $message.Message )
103
107
104
108
if ($DebugTimingInfo ) {
105
109
$sw.Stop ()
106
110
if ($sw.ElapsedMilliseconds -gt $DebugTimingThresholdMs ) {
107
- Write-Warning " Time to parse log entry ${ script:logEntryNum } - $ ( $sw.ElapsedMilliseconds ) ms"
111
+ Write-Warning " Time to parse log entry ${ script:logEntryIndex } - $ ( $sw.ElapsedMilliseconds ) ms"
108
112
}
109
113
}
110
114
111
- $script :logEntryNum ++
115
+ $script :logEntryIndex ++
112
116
}
113
117
114
118
function parseMessage ([string ]$Method ) {
@@ -129,29 +133,29 @@ function Parse-PsesLog {
129
133
$msg = $matches [" msg" ]
130
134
$id = $matches [" id" ]
131
135
$json = parseJsonMessageBody
132
- $result.Message = [PsesJsonRpcMessage ]::new($msg , $id , $json )
136
+ $result.Message = [PsesJsonRpcMessage ]::new($msg , $id , $json.Data , $json .DataSize )
133
137
}
134
138
elseif (($Method -eq ' ReadMessage' ) -and
135
139
($line -match ' \s+Received event '' (?<msg>[^'' ]+)'' ' )) {
136
140
$result.MessageType = [PsesMessageType ]::Notification
137
141
$msg = $matches [" msg" ]
138
142
$json = parseJsonMessageBody
139
- $result.Message = [PsesNotificationMessage ]::new($msg , [PsesNotificationSource ]::Client, $json )
143
+ $result.Message = [PsesNotificationMessage ]::new($msg , [PsesNotificationSource ]::Client, $json.Data , $json .DataSize )
140
144
}
141
145
elseif (($Method -eq ' WriteMessage' ) -and
142
146
($line -match ' \s+Writing Response '' (?<msg>[^'' ]+)'' with id (?<id>\d+)' )) {
143
147
$result.MessageType = [PsesMessageType ]::Response
144
148
$msg = $matches [" msg" ]
145
149
$id = $matches [" id" ]
146
150
$json = parseJsonMessageBody
147
- $result.Message = [PsesJsonRpcMessage ]::new($msg , $id , $json )
151
+ $result.Message = [PsesJsonRpcMessage ]::new($msg , $id , $json.Data , $json .DataSize )
148
152
}
149
153
elseif (($Method -eq ' WriteMessage' ) -and
150
154
($line -match ' \s+Writing event '' (?<msg>[^'' ]+)'' ' )) {
151
155
$result.MessageType = [PsesMessageType ]::Notification
152
156
$msg = $matches [" msg" ]
153
157
$json = parseJsonMessageBody
154
- $result.Message = [PsesNotificationMessage ]::new($msg , [PsesNotificationSource ]::Server, $json )
158
+ $result.Message = [PsesNotificationMessage ]::new($msg , [PsesNotificationSource ]::Server, $json.Data , $json .DataSize )
155
159
}
156
160
else {
157
161
$result.MessageType = [PsesMessageType ]::Log
@@ -199,24 +203,30 @@ function Parse-PsesLog {
199
203
}
200
204
201
205
function parseJsonMessageBody () {
206
+ $result = [PSCustomObject ]@ {
207
+ Data = $null
208
+ DataSize = 0
209
+ }
210
+
202
211
$obj = $null
203
212
204
213
if ($SkipRpcMessageBody ) {
205
214
parseMessageBody - Discard
206
- return $null
215
+ return $result
207
216
}
208
217
else {
209
- $result = parseMessageBody
218
+ $result.Data = parseMessageBody
219
+ $result.DataSize = $result.Data.Length
210
220
}
211
221
212
222
try {
213
- $obj = $result.Trim () | ConvertFrom-Json
223
+ $result .Data = $result.Data .Trim () | ConvertFrom-Json
214
224
}
215
225
catch {
216
226
Write-Error " Failed parsing JSON message body with error: $_ "
217
227
}
218
228
219
- $obj
229
+ $result
220
230
}
221
231
}
222
232
0 commit comments