Files
Yeuoly 31d7c7417e feat[0.1.0]: introduce 'run' command for local plugin execution (#283)
* feat: introduce 'run' command for local plugin execution

- Added a new command `run` to launch plugins locally, allowing communication through stdin/stdout.
- Removed the previous `test` command and its associated functionality to streamline the plugin testing process.

* feat: enhance 'run' command with TCP support

- Introduced a new `RunPluginPayload` structure to encapsulate plugin execution parameters.
- Added TCP communication mode to the `run` command, allowing multiple client connections.
- Updated command flags to configure run mode and logging options.
- Implemented client handling and server creation for both stdin/stdout and TCP modes.

* docs: improve comments in RunPlugin function for clarity

- Enhanced comments to provide clearer explanations of the plugin decoding process and the creation of client streams for both stdin/stdout and TCP modes.
- Updated comments to reflect the functionality and behavior of the plugin execution flow.

* refactor: update command structure and enhance plugin invocation handling

- Changed the command structure to add `runPluginCommand` under `pluginCommand` for better organization.
- Introduced `InvokePluginPayload` type to encapsulate plugin invocation details.
- Enhanced `RunPlugin` function to handle responses and errors more effectively, including logging to stdout.
- Updated client handling to support session management and improved error handling during plugin invocation.
- Renamed TCP server creation function for consistency.

* feat: enhance plugin response handling and logging capabilities

- Added a new flag `--response-format` to specify the output format (text or json) for plugin responses.
- Introduced a `logger` to manage logging output to stdout with timestamps and file information.
- Updated `logResponse` and `systemLog` functions to handle different response formats.
- Enhanced `handleClient` and `RunPlugin` functions to utilize the new response format feature.
- Implemented signal handling to clean up temporary directories on shutdown.

* feat: enhance plugin response structure and logging

- Added `InvokeID` to `InvokePluginPayload` and `GenericResponse` for better tracking of plugin invocations.
- Updated `logResponse` to include `InvokeID` in error responses for improved debugging.
- Enhanced client handling in `handleClient` to log plugin readiness and received requests.
- Refactored client stream creation for better readability and consistency.

* feat: add plugin invoke end response type and logging

- Introduced `GENERIC_RESPONSE_TYPE_PLUGIN_INVOKE_END` to enhance response tracking for plugin invocations.
- Updated `handleClient` to log the end of plugin invocation, improving visibility into the plugin lifecycle.

* chore: remove fullfeature tags
2025-05-16 14:20:29 +08:00

68 lines
1.6 KiB
Go

package log
/*
log module is used to write log info to log file
open a log file when log was created, and close it when log was destroyed
*/
import (
"fmt"
go_log "log"
"os"
)
var show_log bool = true
var logger = go_log.New(os.Stdout, "", go_log.Ldate|go_log.Ltime|go_log.Lshortfile)
const (
LOG_LEVEL_DEBUG_COLOR = "\033[34m"
LOG_LEVEL_INFO_COLOR = "\033[32m"
LOG_LEVEL_WARN_COLOR = "\033[33m"
LOG_LEVEL_ERROR_COLOR = "\033[31m"
LOG_LEVEL_COLOR_END = "\033[0m"
)
func writeLog(level string, format string, stdout bool, v ...interface{}) {
//write log
format = fmt.Sprintf("["+level+"]"+format, v...)
if show_log && stdout {
if level == "DEBUG" {
logger.Output(3, LOG_LEVEL_DEBUG_COLOR+format+LOG_LEVEL_COLOR_END)
} else if level == "INFO" {
logger.Output(3, LOG_LEVEL_INFO_COLOR+format+LOG_LEVEL_COLOR_END)
} else if level == "WARN" {
logger.Output(3, LOG_LEVEL_WARN_COLOR+format+LOG_LEVEL_COLOR_END)
} else if level == "ERROR" {
logger.Output(3, LOG_LEVEL_ERROR_COLOR+format+LOG_LEVEL_COLOR_END)
} else if level == "PANIC" {
logger.Output(3, LOG_LEVEL_ERROR_COLOR+format+LOG_LEVEL_COLOR_END)
panic(format)
}
}
}
func SetLogVisibility(show bool) {
show_log = show
}
func Debug(format string, v ...interface{}) {
writeLog("DEBUG", format, true, v...)
}
func Info(format string, v ...interface{}) {
writeLog("INFO", format, true, v...)
}
func Warn(format string, v ...interface{}) {
writeLog("WARN", format, true, v...)
}
func Error(format string, v ...interface{}) {
writeLog("ERROR", format, true, v...)
}
func Panic(format string, v ...interface{}) {
writeLog("PANIC", format, true, v...)
}