Skip to content

Commit

Permalink
feat: update helper functions for plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-hm19 committed Nov 29, 2024
1 parent 0278005 commit ba26bb1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/module/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ type Plugin struct {
// Module represents the real module impl
Module Module
// dir represents the working directory of the plugin binary, which will be typically set as the stack path.
dir string
dir string
ModuleName string
}

func NewPlugin(key, dir string) (*Plugin, error) {
Expand Down Expand Up @@ -77,6 +78,7 @@ func (p *Plugin) initModule() error {
return err
}
pluginName := prefix[0] + "-" + prefix[1]
p.ModuleName = pluginName
client, err := NewPluginClient(pluginPath, pluginName, p.dir)
if err != nil {
return err
Expand Down Expand Up @@ -131,16 +133,16 @@ func NewPluginClient(modulePluginPath, moduleName, workingDir string) (*plugin.C
if err != nil {
return nil, err
}
logDir := filepath.Join(dir, log.Folder, Dir)
logDir := filepath.Join(dir, log.Folder, Dir, moduleName)
if _, err := os.Stat(logDir); os.IsNotExist(err) {
if err := os.MkdirAll(logDir, os.ModePerm); err != nil {
return nil, fmt.Errorf("failed to create module log dir: %w", err)
}
}
logFilePath = filepath.Join(logDir, moduleName+".log")
logFile, err := os.Create(logFilePath)
logFile, err := os.OpenFile(logFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return nil, fmt.Errorf("failed to create module log file: %w", err)
return nil, fmt.Errorf("failed to open module %s log file: %w", moduleName, err)
}

// write log to a separate file
Expand Down

0 comments on commit ba26bb1

Please sign in to comment.