forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpop.go
40 lines (34 loc) · 755 Bytes
/
pop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package pop
import (
"fmt"
"log"
"os"
"github.com/fatih/color"
)
var AvailableDialects = []string{"postgres", "mysql", "cockroach"}
// Debug mode, to toggle verbose log traces
var Debug = false
// Color mode, to toggle colored logs
var Color = true
var logger = log.New(os.Stdout, "[POP] ", log.LstdFlags)
// Log a formatted string to the logger
var Log = func(s string, args ...interface{}) {
if Debug {
if len(args) > 0 {
xargs := make([]string, len(args))
for i, a := range args {
switch a.(type) {
case string:
xargs[i] = fmt.Sprintf("%q", a)
default:
xargs[i] = fmt.Sprintf("%v", a)
}
}
s = fmt.Sprintf("%s | %s", s, xargs)
}
if Color {
s = color.YellowString(s)
}
logger.Println(s)
}
}