@@ -5,18 +5,38 @@ import com.compiler.server.model.ProjectSeveriry
55import com.compiler.server.model.TextInterval
66import org.jetbrains.kotlin.buildtools.api.KotlinLogger
77
8+
9+ /* *
10+ * CompilationLogger is used for collecting logs from compilation with kotlin-build-tools-api.
11+ * It is passed as an argument while executing a compilation operation. It collects logs returned
12+ * during compilation, interprets returned strings, and saves logs in the map based on their severity.
13+ * The map is later used to provide information about warnings and errors in the user's code.
14+ *
15+ * KotlinLogger interface will be changed in the future to contain more log details.
16+ * Implementation of the CompilationLogger should be therefore updated after KT-80963 is implemented.
17+ *
18+ * @property isDebugEnabled A flag to indicate whether debug-level logging is enabled for the logger.
19+ * If true, all messages are printed to the standard output.
20+ */
821class CompilationLogger (
922 override val isDebugEnabled : Boolean = false ,
1023) : KotlinLogger {
1124
25+ /* *
26+ * Stores a collection of compilation logs organized by file paths.
27+ *
28+ * The map keys represent file paths as strings, and the associated values are mutable lists of
29+ * `ErrorDescriptor` objects containing details about compilation issues, such as error messages,
30+ * intervals, severity, and optional class names.
31+ */
1232 var compilationLogs: Map <String , MutableList <ErrorDescriptor >> = emptyMap()
1333
1434 override fun debug (msg : String ) {
1535 if (isDebugEnabled) println (" [DEBUG] $msg " )
1636 }
1737
1838 override fun error (msg : String , throwable : Throwable ? ) {
19- if (isDebugEnabled) System .err. println (" [ERROR] $msg " + (throwable?.let { " : ${it.message} " } ? : " " ))
39+ if (isDebugEnabled) println (" [ERROR] $msg " + (throwable?.let { " : ${it.message} " } ? : " " ))
2040 try {
2141 addCompilationLog(msg, ProjectSeveriry .ERROR , classNameOverride = null )
2242 } catch (_: Exception ) {}
@@ -31,12 +51,22 @@ class CompilationLogger(
3151 }
3252
3353 override fun warn (msg : String , throwable : Throwable ? ) {
34- if (isDebugEnabled) System .err. println (" [WARN] $msg " + (throwable?.let { " : ${it.message} " } ? : " " ))
54+ if (isDebugEnabled) println (" [WARN] $msg " + (throwable?.let { " : ${it.message} " } ? : " " ))
3555 try {
3656 addCompilationLog(msg, ProjectSeveriry .WARNING , classNameOverride = " WARNING" )
3757 } catch (_: Exception ) {}
3858 }
3959
60+
61+ /* *
62+ * Adds a compilation log entry to the `compilationLogs` map based on the sting log.
63+ *
64+ * @param msg The raw log message containing information about the compilation event,
65+ * including the file path and error details.
66+ * @param severity The severity level of the compilation event, represented by the `ProjectSeveriry` enum.
67+ * @param classNameOverride An optional override for the class name that will be recorded in the log.
68+ * If null, it will be derived from the file path in the message.
69+ */
4070 private fun addCompilationLog (msg : String , severity : ProjectSeveriry , classNameOverride : String? ) {
4171 val path = msg.split(" " )[0 ]
4272 val className = path.split(" /" ).last().split(" ." ).first()
0 commit comments