Skip to content

Commit c46cdf7

Browse files
refactor: replace map[string]interface{} with logrus.Fields in logging
1 parent 0235e00 commit c46cdf7

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

config/tools-installer.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import (
1111
"path/filepath"
1212
"strings"
1313
"text/template"
14+
15+
"github.com/sirupsen/logrus"
1416
)
1517

1618
// InstallTools installs all tools defined in the configuration
1719
func InstallTools(config *ConfigType, registry string) error {
1820
var failedTools []string
1921

2022
for name, toolInfo := range config.Tools() {
21-
logger.Info("Starting tool installation", map[string]interface{}{
23+
logger.Info("Starting tool installation", logrus.Fields{
2224
"tool": name,
2325
"version": toolInfo.Version,
2426
"runtime": toolInfo.Runtime,
@@ -27,7 +29,7 @@ func InstallTools(config *ConfigType, registry string) error {
2729
fmt.Printf("Installing tool: %s v%s...\n", name, toolInfo.Version)
2830
err := InstallTool(name, toolInfo, registry)
2931
if err != nil {
30-
logger.Error("Failed to install tool", map[string]interface{}{
32+
logger.Error("Failed to install tool", logrus.Fields{
3133
"tool": name,
3234
"version": toolInfo.Version,
3335
"runtime": toolInfo.Runtime,
@@ -37,7 +39,7 @@ func InstallTools(config *ConfigType, registry string) error {
3739
continue
3840
}
3941

40-
logger.Info("Successfully installed tool", map[string]interface{}{
42+
logger.Info("Successfully installed tool", logrus.Fields{
4143
"tool": name,
4244
"version": toolInfo.Version,
4345
"runtime": toolInfo.Runtime,
@@ -55,7 +57,7 @@ func InstallTools(config *ConfigType, registry string) error {
5557
func InstallTool(name string, toolInfo *plugins.ToolInfo, registry string) error {
5658
// Check if the tool is already installed
5759
if isToolInstalled(toolInfo) {
58-
logger.Info("Tool already installed", map[string]interface{}{
60+
logger.Info("Tool already installed", logrus.Fields{
5961
"tool": name,
6062
"version": toolInfo.Version,
6163
"runtime": toolInfo.Runtime,
@@ -73,7 +75,7 @@ func InstallTool(name string, toolInfo *plugins.ToolInfo, registry string) error
7375
// Check if this is a download-based tool (like trivy) or a runtime-based tool (like eslint)
7476
if toolInfo.DownloadURL != "" {
7577
// This is a download-based tool
76-
logger.Debug("Installing download-based tool", map[string]interface{}{
78+
logger.Debug("Installing download-based tool", logrus.Fields{
7779
"tool": name,
7880
"version": toolInfo.Version,
7981
"downloadURL": toolInfo.DownloadURL,
@@ -84,7 +86,7 @@ func InstallTool(name string, toolInfo *plugins.ToolInfo, registry string) error
8486

8587
// Handle Python tools differently
8688
if toolInfo.Runtime == "python" {
87-
logger.Debug("Installing Python tool", map[string]interface{}{
89+
logger.Debug("Installing Python tool", logrus.Fields{
8890
"tool": name,
8991
"version": toolInfo.Version,
9092
})
@@ -93,7 +95,7 @@ func InstallTool(name string, toolInfo *plugins.ToolInfo, registry string) error
9395
}
9496

9597
// For runtime-based tools
96-
logger.Debug("Installing runtime-based tool", map[string]interface{}{
98+
logger.Debug("Installing runtime-based tool", logrus.Fields{
9799
"tool": name,
98100
"version": toolInfo.Version,
99101
"runtime": toolInfo.Runtime,
@@ -131,7 +133,7 @@ func installRuntimeTool(name string, toolInfo *plugins.ToolInfo, registry string
131133
return fmt.Errorf("failed to prepare registry command: %w", err)
132134
}
133135

134-
logger.Debug("Setting registry", map[string]interface{}{
136+
logger.Debug("Setting registry", logrus.Fields{
135137
"tool": name,
136138
"packageManager": packageManagerName,
137139
"packageManagerBin": packageManagerBinary,
@@ -152,7 +154,7 @@ func installRuntimeTool(name string, toolInfo *plugins.ToolInfo, registry string
152154
return fmt.Errorf("failed to prepare install command: %w", err)
153155
}
154156

155-
logger.Debug("Installing tool", map[string]interface{}{
157+
logger.Debug("Installing tool", logrus.Fields{
156158
"tool": name,
157159
"version": toolInfo.Version,
158160
"packageManager": packageManagerName,
@@ -167,7 +169,7 @@ func installRuntimeTool(name string, toolInfo *plugins.ToolInfo, registry string
167169
return fmt.Errorf("failed to install tool: %s: %w", string(output), err)
168170
}
169171

170-
logger.Debug("Tool installation completed", map[string]interface{}{
172+
logger.Debug("Tool installation completed", logrus.Fields{
171173
"tool": name,
172174
"version": toolInfo.Version,
173175
})
@@ -184,7 +186,7 @@ func installDownloadBasedTool(toolInfo *plugins.ToolInfo) error {
184186
_, err := os.Stat(downloadPath)
185187
if os.IsNotExist(err) {
186188
// Download the file
187-
logger.Debug("Downloading tool", map[string]interface{}{
189+
logger.Debug("Downloading tool", logrus.Fields{
188190
"tool": toolInfo.Name,
189191
"version": toolInfo.Version,
190192
"downloadURL": toolInfo.DownloadURL,
@@ -197,7 +199,7 @@ func installDownloadBasedTool(toolInfo *plugins.ToolInfo) error {
197199
} else if err != nil {
198200
return fmt.Errorf("error checking for existing download: %w", err)
199201
} else {
200-
logger.Debug("Using existing tool download", map[string]interface{}{
202+
logger.Debug("Using existing tool download", logrus.Fields{
201203
"tool": toolInfo.Name,
202204
"version": toolInfo.Version,
203205
"downloadPath": downloadPath,
@@ -217,8 +219,8 @@ func installDownloadBasedTool(toolInfo *plugins.ToolInfo) error {
217219
return fmt.Errorf("failed to create installation directory: %w", err)
218220
}
219221

220-
// Extract directly to the installation directory
221-
logger.Debug("Extracting tool", map[string]interface{}{
222+
// Extract based on file extension
223+
logger.Debug("Extracting tool", logrus.Fields{
222224
"tool": toolInfo.Name,
223225
"version": toolInfo.Version,
224226
"fileName": fileName,
@@ -243,15 +245,15 @@ func installDownloadBasedTool(toolInfo *plugins.ToolInfo) error {
243245
}
244246
}
245247

246-
logger.Debug("Tool extraction completed", map[string]interface{}{
248+
logger.Debug("Tool extraction completed", logrus.Fields{
247249
"tool": toolInfo.Name,
248250
"version": toolInfo.Version,
249251
})
250252
return nil
251253
}
252254

253255
func installPythonTool(name string, toolInfo *plugins.ToolInfo) error {
254-
logger.Debug("Starting Python tool installation", map[string]interface{}{
256+
logger.Debug("Starting Python tool installation", logrus.Fields{
255257
"tool": toolInfo.Name,
256258
"version": toolInfo.Version,
257259
})
@@ -267,7 +269,7 @@ func installPythonTool(name string, toolInfo *plugins.ToolInfo) error {
267269
}
268270

269271
// Create venv
270-
logger.Debug("Creating Python virtual environment", map[string]interface{}{
272+
logger.Debug("Creating Python virtual environment", logrus.Fields{
271273
"tool": toolInfo.Name,
272274
"version": toolInfo.Version,
273275
"venvDir": filepath.Join(toolInfo.InstallDir, "venv"),
@@ -281,7 +283,7 @@ func installPythonTool(name string, toolInfo *plugins.ToolInfo) error {
281283

282284
// Install the tool using pip from venv
283285
pipPath := filepath.Join(toolInfo.InstallDir, "venv", "bin", "pip")
284-
logger.Debug("Installing Python package", map[string]interface{}{
286+
logger.Debug("Installing Python package", logrus.Fields{
285287
"tool": toolInfo.Name,
286288
"version": toolInfo.Version,
287289
"pipPath": pipPath,
@@ -293,7 +295,7 @@ func installPythonTool(name string, toolInfo *plugins.ToolInfo) error {
293295
return fmt.Errorf("failed to install tool: %s\nError: %w", string(output), err)
294296
}
295297

296-
logger.Debug("Python tool installation completed", map[string]interface{}{
298+
logger.Debug("Python tool installation completed", logrus.Fields{
297299
"tool": toolInfo.Name,
298300
"version": toolInfo.Version,
299301
})

0 commit comments

Comments
 (0)