@@ -107,7 +107,7 @@ open class LoggerBase(val logCounter: LogCounter) {
107
107
file_number_diagnostic_number = 0
108
108
}
109
109
110
- fun diagnostic (tw : TrapWriter , severity : Severity , msg : String , extraInfo : String? , locationString : String? = null, mkLocationId : () -> Label <DbLocation > = { tw .unknownLocation }) {
110
+ fun diagnostic (dtw : DiagnosticTrapWriter , severity : Severity , msg : String , extraInfo : String? , locationString : String? = null, mkLocationId : () -> Label <DbLocation > = { dtw .unknownLocation }) {
111
111
val diagnosticLoc = getDiagnosticLocation()
112
112
val diagnosticLocStr = if (diagnosticLoc == null ) " <unknown location>" else diagnosticLoc
113
113
val suffix =
@@ -121,7 +121,7 @@ open class LoggerBase(val logCounter: LogCounter) {
121
121
// counting machinery
122
122
if (verbosity >= 1 ) {
123
123
val message = " Severity mismatch ($severity vs ${oldInfo.first} ) at $diagnosticLoc "
124
- emitDiagnostic(tw , Severity .Error , " Inconsistency" , message, message)
124
+ emitDiagnostic(dtw , Severity .Error , " Inconsistency" , message, message)
125
125
}
126
126
}
127
127
val newCount = oldInfo.second + 1
@@ -149,18 +149,18 @@ open class LoggerBase(val logCounter: LogCounter) {
149
149
fullMsgBuilder.append(suffix)
150
150
151
151
val fullMsg = fullMsgBuilder.toString()
152
- emitDiagnostic(tw , severity, diagnosticLocStr, msg, fullMsg, locationString, mkLocationId)
152
+ emitDiagnostic(dtw , severity, diagnosticLocStr, msg, fullMsg, locationString, mkLocationId)
153
153
}
154
154
155
- private fun emitDiagnostic (tw : TrapWriter , severity : Severity , diagnosticLocStr : String , msg : String , fullMsg : String , locationString : String? = null, mkLocationId : () -> Label <DbLocation > = { tw .unknownLocation }) {
155
+ private fun emitDiagnostic (dtw : DiagnosticTrapWriter , severity : Severity , diagnosticLocStr : String , msg : String , fullMsg : String , locationString : String? = null, mkLocationId : () -> Label <DbLocation > = { dtw .unknownLocation }) {
156
156
val locStr = if (locationString == null ) " " else " At " + locationString + " : "
157
157
val kind = if (severity <= Severity .WarnHigh ) " WARN" else " ERROR"
158
158
val logMessage = LogMessage (kind, " Diagnostic($diagnosticLocStr ): $locStr$fullMsg " )
159
159
// We don't actually make the location until after the `return` above
160
160
val locationId = mkLocationId()
161
- val diagLabel = tw .getFreshIdLabel<DbDiagnostic >()
162
- tw .writeDiagnostics(diagLabel, " CodeQL Kotlin extractor" , severity.sev, " " , msg, " ${logMessage.timestamp} $fullMsg " , locationId)
163
- tw .writeDiagnostic_for(diagLabel, StringLabel (" compilation" ), file_number, file_number_diagnostic_number++ )
161
+ val diagLabel = dtw .getFreshIdLabel<DbDiagnostic >()
162
+ dtw .writeDiagnostics(diagLabel, " CodeQL Kotlin extractor" , severity.sev, " " , msg, " ${logMessage.timestamp} $fullMsg " , locationId)
163
+ dtw .writeDiagnostic_for(diagLabel, StringLabel (" compilation" ), file_number, file_number_diagnostic_number++ )
164
164
logStream.write(logMessage.toJsonLine())
165
165
}
166
166
@@ -188,18 +188,18 @@ open class LoggerBase(val logCounter: LogCounter) {
188
188
}
189
189
}
190
190
191
- fun warn (tw : TrapWriter , msg : String , extraInfo : String? ) {
191
+ fun warn (dtw : DiagnosticTrapWriter , msg : String , extraInfo : String? ) {
192
192
if (verbosity >= 2 ) {
193
- diagnostic(tw , Severity .Warn , msg, extraInfo)
193
+ diagnostic(dtw , Severity .Warn , msg, extraInfo)
194
194
}
195
195
}
196
- fun error (tw : TrapWriter , msg : String , extraInfo : String? ) {
196
+ fun error (dtw : DiagnosticTrapWriter , msg : String , extraInfo : String? ) {
197
197
if (verbosity >= 1 ) {
198
- diagnostic(tw , Severity .Error , msg, extraInfo)
198
+ diagnostic(dtw , Severity .Error , msg, extraInfo)
199
199
}
200
200
}
201
201
202
- fun printLimitedDiagnosticCounts (tw : TrapWriter ) {
202
+ fun printLimitedDiagnosticCounts (dtw : DiagnosticTrapWriter ) {
203
203
for ((caller, info) in logCounter.diagnosticInfo) {
204
204
val severity = info.first
205
205
val count = info.second
@@ -209,7 +209,7 @@ open class LoggerBase(val logCounter: LogCounter) {
209
209
// to be an error regardless.
210
210
val message = " Total of $count diagnostics (reached limit of ${logCounter.diagnosticLimit} ) from $caller ."
211
211
if (verbosity >= 1 ) {
212
- emitDiagnostic(tw , severity, " Limit" , message, message)
212
+ emitDiagnostic(dtw , severity, " Limit" , message, message)
213
213
}
214
214
}
215
215
}
@@ -224,28 +224,28 @@ open class LoggerBase(val logCounter: LogCounter) {
224
224
}
225
225
}
226
226
227
- open class Logger (val loggerBase : LoggerBase , open val tw : TrapWriter ) {
227
+ open class Logger (val loggerBase : LoggerBase , open val dtw : DiagnosticTrapWriter ) {
228
228
fun flush () {
229
- tw .flush()
229
+ dtw .flush()
230
230
loggerBase.flush()
231
231
}
232
232
233
233
fun trace (msg : String ) {
234
- loggerBase.trace(tw , msg)
234
+ loggerBase.trace(dtw , msg)
235
235
}
236
236
fun trace (msg : String , exn : Throwable ) {
237
237
trace(msg + " \n " + exn.stackTraceToString())
238
238
}
239
239
fun debug (msg : String ) {
240
- loggerBase.debug(tw , msg)
240
+ loggerBase.debug(dtw , msg)
241
241
}
242
242
243
243
fun info (msg : String ) {
244
- loggerBase.info(tw , msg)
244
+ loggerBase.info(dtw , msg)
245
245
}
246
246
247
247
private fun warn (msg : String , extraInfo : String? ) {
248
- loggerBase.warn(tw , msg, extraInfo)
248
+ loggerBase.warn(dtw , msg, extraInfo)
249
249
}
250
250
fun warn (msg : String , exn : Throwable ) {
251
251
warn(msg, exn.stackTraceToString())
@@ -255,7 +255,7 @@ open class Logger(val loggerBase: LoggerBase, open val tw: TrapWriter) {
255
255
}
256
256
257
257
private fun error (msg : String , extraInfo : String? ) {
258
- loggerBase.error(tw , msg, extraInfo)
258
+ loggerBase.error(dtw , msg, extraInfo)
259
259
}
260
260
fun error (msg : String ) {
261
261
error(msg, null )
@@ -265,16 +265,16 @@ open class Logger(val loggerBase: LoggerBase, open val tw: TrapWriter) {
265
265
}
266
266
}
267
267
268
- class FileLogger (loggerBase : LoggerBase , override val tw : FileTrapWriter ): Logger(loggerBase, tw ) {
268
+ class FileLogger (loggerBase : LoggerBase , val ftw : FileTrapWriter ): Logger(loggerBase, ftw.getDiagnosticTrapWriter() ) {
269
269
fun warnElement (msg : String , element : IrElement , exn : Throwable ? = null) {
270
- val locationString = tw .getLocationString(element)
271
- val mkLocationId = { tw .getLocation(element) }
272
- loggerBase.diagnostic(tw , Severity .Warn , msg, exn?.stackTraceToString(), locationString, mkLocationId)
270
+ val locationString = ftw .getLocationString(element)
271
+ val mkLocationId = { ftw .getLocation(element) }
272
+ loggerBase.diagnostic(ftw.getDiagnosticTrapWriter() , Severity .Warn , msg, exn?.stackTraceToString(), locationString, mkLocationId)
273
273
}
274
274
275
275
fun errorElement (msg : String , element : IrElement , exn : Throwable ? = null) {
276
- val locationString = tw .getLocationString(element)
277
- val mkLocationId = { tw .getLocation(element) }
278
- loggerBase.diagnostic(tw , Severity .Error , msg, exn?.stackTraceToString(), locationString, mkLocationId)
276
+ val locationString = ftw .getLocationString(element)
277
+ val mkLocationId = { ftw .getLocation(element) }
278
+ loggerBase.diagnostic(ftw.getDiagnosticTrapWriter() , Severity .Error , msg, exn?.stackTraceToString(), locationString, mkLocationId)
279
279
}
280
280
}
0 commit comments