Merge pull request #430 from devchat-ai/ide-logging

Implement ide_logging to handle different log levels
This commit is contained in:
boob.yang 2024-02-02 08:52:23 +08:00 committed by GitHub
commit b935da2746
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 24 deletions

View File

@ -1,14 +1,10 @@
import { logger } from "../../util/logger";
export async function logInfo(message: string) {
logger.channel()?.info(message);
return true;
}
export async function logWarn(message: string) {
logger.channel()?.warn(message);
return true;
}
export async function logError(message: string) {
logger.channel()?.error(message);
return true;
export async function ideLogging(level: string, message: string) {
if (typeof logger.channel()?.[level] === "function") {
// level is one of "info", "warn", "error", "debug"
logger.channel()?.[level](message);
return true;
}
return false;
}

View File

@ -5,7 +5,7 @@ import { logger } from "../util/logger";
import { getServicePort } from "./endpoints/getServicePort";
import { installPythonEnv } from "./endpoints/installPythonEnv";
import { logError, logInfo, logWarn } from "./endpoints/ideLogging";
import { ideLogging} from "./endpoints/ideLogging";
import { updateSlashCommands } from "./endpoints/updateSlashCommands";
import { ideLanguage } from "./endpoints/ideLanguage";
import { LegacyEndpoints } from "./endpoints/legacy";
@ -32,17 +32,9 @@ const functionRegistry: any = {
keys: [],
handler: ideLanguage,
},
"/log_info": {
keys: ["message"],
handler: logInfo,
},
"/log_warn": {
keys: ["message"],
handler: logWarn,
},
"/log_error": {
keys: ["message"],
handler: logError,
"/ide_logging": {
keys: ["level", "message"],
handler: ideLogging,
},
"/get_document_symbols": {
keys: ["abspath"],

View File

@ -2,6 +2,8 @@
* Type definitions for IDE Service Protocol
*/
export namespace IDEService {
export type LogLevel = "info" | "warn" | "error" | "debug";
export interface Position {
line: number; // 0-based
character: number; // 0-based
@ -14,7 +16,7 @@ export namespace IDEService {
export interface SymbolNode {
name: string;
kind: string;
kind: string;
range: Range;
children: SymbolNode[];
}