Skip to content

Commit 6e61304

Browse files
committed
Make logs better
1 parent 7b9a399 commit 6e61304

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

kill-mysql-query.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,7 @@ func killQueries(config configuration.Config) {
6060
}
6161

6262
showKillPrompt(longQueries, dbConn, config)
63-
fmt.Println()
64-
fmt.Println()
65-
fmt.Println()
66-
fmt.Println("-----------------------------------")
6763
fmt.Println("💫 Rechecking...")
68-
fmt.Println("-----------------------------------")
6964
}
7065
}
7166

@@ -129,13 +124,16 @@ func showKillPrompt(longQueries []mysql.MysqlProcess, dbConn *sqlx.DB, config co
129124
os.Exit(0)
130125
}
131126

132-
if len(longQueries) == 1 {
133-
query := longQueries[0]
134-
cyan := color.FgCyan.Render
135-
label := fmt.Sprintf("🐢 This query is running for %s second(s) in `%s` database:\n\n%s\n\n", cyan(query.Time), cyan(query.DB), cyan(query.Info.String))
127+
cyan := color.FgCyan.Render
128+
green := color.FgGreen.Render
136129

130+
if len(longQueries) == 1 {
137131
fmt.Println()
138132
fmt.Println()
133+
fmt.Printf("❄️ Found %s long running query!\n", cyan("1"))
134+
query := longQueries[0]
135+
label := fmt.Sprintf("🐢 This query is running for %s second(s) in the `%s` database:\n\n%s\n\n", cyan(query.Time), cyan(query.DB), cyan(query.TruncatedQuery))
136+
139137
fmt.Println(label)
140138
prompt := promptui.Prompt{
141139
Label: "🧨 Kill it?",
@@ -159,6 +157,11 @@ func showKillPrompt(longQueries []mysql.MysqlProcess, dbConn *sqlx.DB, config co
159157
}
160158

161159
if len(longQueries) > 1 {
160+
fmt.Println()
161+
fmt.Println()
162+
fmt.Printf("❄️ Found %s long running queries!\n", cyan(len(longQueries)))
163+
fmt.Println()
164+
162165
templates := &promptui.SelectTemplates{
163166
Label: "{{ . }}?",
164167
Active: "👉 DB `{{ .DB | cyan }}`, Running Time: {{ .Time | cyan }}s, Query: {{ .TruncatedQuery | cyan }}",
@@ -174,15 +177,14 @@ func showKillPrompt(longQueries []mysql.MysqlProcess, dbConn *sqlx.DB, config co
174177
{{ "Query:" | faint }} {{ .TruncatedQuery }}`,
175178
}
176179

180+
label := fmt.Sprintf("Press %s to confirm. Which one to kill?", green("ENTER"))
177181
prompt := promptui.Select{
178-
Label: "Press enter to select. Which one to kill?",
182+
Label: label,
179183
Items: longQueries,
180184
Templates: templates,
181185
Size: 10,
182186
}
183187

184-
fmt.Println()
185-
fmt.Println()
186188
i, _, err := prompt.Run()
187189

188190
if err != nil {

mysql/query.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"regexp"
88
"text/template"
99

10+
"github.com/gookit/color"
1011
"github.com/mugli/go-kill-mysql-query/configuration"
1112

1213
"github.com/jmoiron/sqlx"
@@ -104,7 +105,7 @@ func truncateString(str string, num int) string {
104105
}
105106

106107
func GetLongRunningQueries(dbConn *sqlx.DB, config configuration.Config) ([]MysqlProcess, error) {
107-
fmt.Println("🕴 Looking for slow queries...")
108+
fmt.Println("🕴 Looking for long running queries...")
108109

109110
longQueries := make([]MysqlProcess, 0)
110111
query, err := generateQuery(config)
@@ -130,12 +131,14 @@ func GetLongRunningQueries(dbConn *sqlx.DB, config configuration.Config) ([]Mysq
130131
}
131132

132133
func KillMySQLProcess(killCommand string, dbConn *sqlx.DB) error {
134+
fmt.Println()
133135
fmt.Println("☠️ Sending kill command...")
134136

135137
if _, err := dbConn.Queryx(killCommand); err != nil {
136138
return err
137139
}
138140

139-
fmt.Println("☠️ Killed it!")
141+
green := color.FgGreen.Render
142+
fmt.Println("☠️ " + green("Killed it!"))
140143
return nil
141144
}

0 commit comments

Comments
 (0)