@@ -107,7 +107,7 @@ open class LoggerBase(val logCounter: LogCounter) {
107107 file_number_diagnostic_number = 0
108108 }
109109
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 }) {
111111 val diagnosticLoc = getDiagnosticLocation()
112112 val diagnosticLocStr = if (diagnosticLoc == null ) " <unknown location>" else diagnosticLoc
113113 val suffix =
@@ -121,7 +121,7 @@ open class LoggerBase(val logCounter: LogCounter) {
121121 // counting machinery
122122 if (verbosity >= 1 ) {
123123 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)
125125 }
126126 }
127127 val newCount = oldInfo.second + 1
@@ -149,18 +149,18 @@ open class LoggerBase(val logCounter: LogCounter) {
149149 fullMsgBuilder.append(suffix)
150150
151151 val fullMsg = fullMsgBuilder.toString()
152- emitDiagnostic(tw , severity, diagnosticLocStr, msg, fullMsg, locationString, mkLocationId)
152+ emitDiagnostic(dtw , severity, diagnosticLocStr, msg, fullMsg, locationString, mkLocationId)
153153 }
154154
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 }) {
156156 val locStr = if (locationString == null ) " " else " At " + locationString + " : "
157157 val kind = if (severity <= Severity .WarnHigh ) " WARN" else " ERROR"
158158 val logMessage = LogMessage (kind, " Diagnostic($diagnosticLocStr ): $locStr$fullMsg " )
159159 // We don't actually make the location until after the `return` above
160160 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++ )
164164 logStream.write(logMessage.toJsonLine())
165165 }
166166
@@ -188,18 +188,18 @@ open class LoggerBase(val logCounter: LogCounter) {
188188 }
189189 }
190190
191- fun warn (tw : TrapWriter , msg : String , extraInfo : String? ) {
191+ fun warn (dtw : DiagnosticTrapWriter , msg : String , extraInfo : String? ) {
192192 if (verbosity >= 2 ) {
193- diagnostic(tw , Severity .Warn , msg, extraInfo)
193+ diagnostic(dtw , Severity .Warn , msg, extraInfo)
194194 }
195195 }
196- fun error (tw : TrapWriter , msg : String , extraInfo : String? ) {
196+ fun error (dtw : DiagnosticTrapWriter , msg : String , extraInfo : String? ) {
197197 if (verbosity >= 1 ) {
198- diagnostic(tw , Severity .Error , msg, extraInfo)
198+ diagnostic(dtw , Severity .Error , msg, extraInfo)
199199 }
200200 }
201201
202- fun printLimitedDiagnosticCounts (tw : TrapWriter ) {
202+ fun printLimitedDiagnosticCounts (dtw : DiagnosticTrapWriter ) {
203203 for ((caller, info) in logCounter.diagnosticInfo) {
204204 val severity = info.first
205205 val count = info.second
@@ -209,7 +209,7 @@ open class LoggerBase(val logCounter: LogCounter) {
209209 // to be an error regardless.
210210 val message = " Total of $count diagnostics (reached limit of ${logCounter.diagnosticLimit} ) from $caller ."
211211 if (verbosity >= 1 ) {
212- emitDiagnostic(tw , severity, " Limit" , message, message)
212+ emitDiagnostic(dtw , severity, " Limit" , message, message)
213213 }
214214 }
215215 }
@@ -224,28 +224,28 @@ open class LoggerBase(val logCounter: LogCounter) {
224224 }
225225}
226226
227- open class Logger (val loggerBase : LoggerBase , open val tw : TrapWriter ) {
227+ open class Logger (val loggerBase : LoggerBase , open val dtw : DiagnosticTrapWriter ) {
228228 fun flush () {
229- tw .flush()
229+ dtw .flush()
230230 loggerBase.flush()
231231 }
232232
233233 fun trace (msg : String ) {
234- loggerBase.trace(tw , msg)
234+ loggerBase.trace(dtw , msg)
235235 }
236236 fun trace (msg : String , exn : Throwable ) {
237237 trace(msg + " \n " + exn.stackTraceToString())
238238 }
239239 fun debug (msg : String ) {
240- loggerBase.debug(tw , msg)
240+ loggerBase.debug(dtw , msg)
241241 }
242242
243243 fun info (msg : String ) {
244- loggerBase.info(tw , msg)
244+ loggerBase.info(dtw , msg)
245245 }
246246
247247 private fun warn (msg : String , extraInfo : String? ) {
248- loggerBase.warn(tw , msg, extraInfo)
248+ loggerBase.warn(dtw , msg, extraInfo)
249249 }
250250 fun warn (msg : String , exn : Throwable ) {
251251 warn(msg, exn.stackTraceToString())
@@ -255,7 +255,7 @@ open class Logger(val loggerBase: LoggerBase, open val tw: TrapWriter) {
255255 }
256256
257257 private fun error (msg : String , extraInfo : String? ) {
258- loggerBase.error(tw , msg, extraInfo)
258+ loggerBase.error(dtw , msg, extraInfo)
259259 }
260260 fun error (msg : String ) {
261261 error(msg, null )
@@ -265,16 +265,16 @@ open class Logger(val loggerBase: LoggerBase, open val tw: TrapWriter) {
265265 }
266266}
267267
268- class FileLogger (loggerBase : LoggerBase , override val tw : FileTrapWriter ): Logger(loggerBase, tw ) {
268+ class FileLogger (loggerBase : LoggerBase , val ftw : FileTrapWriter ): Logger(loggerBase, ftw.getDiagnosticTrapWriter() ) {
269269 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)
273273 }
274274
275275 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)
279279 }
280280}
0 commit comments