File tree Expand file tree Collapse file tree 4 files changed +44
-23
lines changed Expand file tree Collapse file tree 4 files changed +44
-23
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import (
1010 "github.com/picostack/pico/executor"
1111 "github.com/picostack/pico/secret/memory"
1212 "github.com/picostack/pico/task"
13+
14+ _ "github.com/picostack/pico/logger"
1315)
1416
1517func TestMain (m * testing.M ) {
Original file line number Diff line number Diff line change 1+ package logger
2+
3+ import (
4+ "os"
5+ "strconv"
6+ "strings"
7+
8+ "go.uber.org/zap"
9+ "go.uber.org/zap/zapcore"
10+ )
11+
12+ func init () {
13+ // constructs a logger and replaces the default global logger
14+ var config zap.Config
15+ if d , e := strconv .ParseBool (os .Getenv ("DEVELOPMENT" )); d && e == nil || isInTests () {
16+ config = zap .NewDevelopmentConfig ()
17+ } else {
18+ config = zap .NewProductionConfig ()
19+ }
20+ config .EncoderConfig .EncodeTime = zapcore .ISO8601TimeEncoder
21+ config .DisableStacktrace = true
22+ if d , e := strconv .ParseBool (os .Getenv ("DEBUG" )); d && e == nil || isInTests () {
23+ config .Level = zap .NewAtomicLevelAt (zap .DebugLevel )
24+ }
25+ logger , err := config .Build ()
26+ if err != nil {
27+ panic (err )
28+ }
29+ zap .ReplaceGlobals (logger )
30+ }
31+
32+ func isInTests () bool {
33+ for _ , arg := range os .Args {
34+ if strings .HasPrefix (arg , "-test.v=" ) {
35+ return true
36+ }
37+ }
38+ return false
39+ }
Original file line number Diff line number Diff line change @@ -4,40 +4,19 @@ import (
44 "context"
55 "os"
66 "os/signal"
7- "strconv"
87 "time"
98
109 _ "github.com/joho/godotenv/autoload"
1110 "github.com/pkg/errors"
1211 "github.com/urfave/cli"
1312 "go.uber.org/zap"
14- "go.uber.org/zap/zapcore"
1513
14+ _ "github.com/picostack/pico/logger"
1615 "github.com/picostack/pico/service"
1716)
1817
1918var version = "master"
2019
21- func init () {
22- // constructs a logger and replaces the default global logger
23- var config zap.Config
24- if d , e := strconv .ParseBool (os .Getenv ("DEVELOPMENT" )); d && e == nil {
25- config = zap .NewDevelopmentConfig ()
26- } else {
27- config = zap .NewProductionConfig ()
28- }
29- config .EncoderConfig .EncodeTime = zapcore .ISO8601TimeEncoder
30- config .DisableStacktrace = true
31- if d , e := strconv .ParseBool (os .Getenv ("DEBUG" )); d && e == nil {
32- config .Level = zap .NewAtomicLevelAt (zap .DebugLevel )
33- }
34- logger , err := config .Build ()
35- if err != nil {
36- panic (err )
37- }
38- zap .ReplaceGlobals (logger )
39- }
40-
4120func main () {
4221 app := cli .NewApp ()
4322
Original file line number Diff line number Diff line change @@ -6,13 +6,14 @@ import (
66 "time"
77
88 "github.com/picostack/pico/task"
9+
10+ _ "github.com/picostack/pico/logger"
911)
1012
1113var w * GitWatcher
1214var bus chan task.ExecutionTask
1315
1416func TestMain (m * testing.M ) {
15- os .Setenv ("DEBUG" , "1" )
1617 bus = make (chan task.ExecutionTask , 16 )
1718 w = NewGitWatcher (".test" , bus , time .Second , nil )
1819
You can’t perform that action at this time.
0 commit comments