diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/infrastructure/LanguageClientAwareAppender.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/infrastructure/LanguageClientAwareAppender.java new file mode 100644 index 00000000000..43140d6138d --- /dev/null +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/infrastructure/LanguageClientAwareAppender.java @@ -0,0 +1,62 @@ +/* + * This file is a part of BSL Language Server. + * + * Copyright (c) 2018-2023 + * Alexey Sosnoviy , Nikita Fedkin and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * BSL Language Server is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * BSL Language Server is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with BSL Language Server. + */ +package com.github._1c_syntax.bsl.languageserver.infrastructure; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.ConsoleAppender; +import com.github._1c_syntax.bsl.languageserver.LanguageClientHolder; +import jakarta.annotation.Nullable; +import lombok.Setter; +import org.eclipse.lsp4j.MessageParams; +import org.eclipse.lsp4j.MessageType; +import org.eclipse.lsp4j.services.LanguageClient; + +import java.io.IOException; + +public class LanguageClientAwareAppender + extends ConsoleAppender { + + protected static LanguageClientAwareAppender INSTANCE; + + @Setter + @Nullable + private LanguageClientHolder clientHolder; + + public LanguageClientAwareAppender() { + super(); + // hacky hack + INSTANCE = this; + } + + @Override + protected void writeOut(ILoggingEvent event) throws IOException { + if (clientHolder != null && clientHolder.isConnected()) { + LanguageClient languageClient = clientHolder.getClient().orElseThrow(); + + var params = new MessageParams(MessageType.Info, event.getFormattedMessage()); + languageClient.logMessage(params); + + return; + } + super.writeOut(event); + } +} diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/infrastructure/LanguageClientAwareAppenderConfiguration.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/infrastructure/LanguageClientAwareAppenderConfiguration.java new file mode 100644 index 00000000000..6b664953116 --- /dev/null +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/infrastructure/LanguageClientAwareAppenderConfiguration.java @@ -0,0 +1,34 @@ +/* + * This file is a part of BSL Language Server. + * + * Copyright (c) 2018-2023 + * Alexey Sosnoviy , Nikita Fedkin and contributors + * + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * BSL Language Server is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * BSL Language Server is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with BSL Language Server. + */ +package com.github._1c_syntax.bsl.languageserver.infrastructure; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class LanguageClientAwareAppenderConfiguration { + + @Bean + public LanguageClientAwareAppender languageClientAwareAppender() { + return LanguageClientAwareAppender.INSTANCE; + } +} diff --git a/src/main/resources/language-client-aware-appender.xml b/src/main/resources/language-client-aware-appender.xml new file mode 100644 index 00000000000..199315fc5fd --- /dev/null +++ b/src/main/resources/language-client-aware-appender.xml @@ -0,0 +1,18 @@ + + + + + + + + ${CONSOLE_LOG_THRESHOLD} + + + ${CONSOLE_LOG_PATTERN} + ${CONSOLE_LOG_CHARSET} + + + \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 00000000000..d32f81a917d --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file