File tree Expand file tree Collapse file tree 3 files changed +24
-6
lines changed
Expand file tree Collapse file tree 3 files changed +24
-6
lines changed Original file line number Diff line number Diff line change 44 "github.com/chanmaoganda/fileshare/cmd/cache"
55 "github.com/chanmaoganda/fileshare/cmd/fileshare/client"
66 "github.com/chanmaoganda/fileshare/cmd/fileshare/server"
7- "github.com/sirupsen/logrus"
87 "github.com/spf13/cobra"
98)
109
@@ -17,11 +16,6 @@ var RootCmd = &cobra.Command{
1716}
1817
1918func init () {
20- logrus .SetLevel (logrus .DebugLevel )
21- logrus .SetFormatter (& logrus.TextFormatter {
22- ForceColors : true ,
23- })
24-
2519 // server commands
2620 RootCmd .AddCommand (server .ServerCmd )
2721
Original file line number Diff line number Diff line change 44 "os"
55
66 "github.com/chanmaoganda/fileshare/internal/config"
7+ "github.com/chanmaoganda/fileshare/internal/pkg/logger"
78 "github.com/chanmaoganda/fileshare/internal/pkg/util"
89 "github.com/chanmaoganda/fileshare/internal/service"
910 "github.com/sirupsen/logrus"
@@ -16,6 +17,7 @@ func SetupClient(cmd *cobra.Command, args []string) error {
1617 logrus .Error (err )
1718 return err
1819 }
20+ logger .SetupLogger ()
1921 service .InitClientService ()
2022 // if directory cannot be set correctly, following actions will panic
2123 return setupDirectory ()
@@ -27,6 +29,7 @@ func SetupServer(cmd *cobra.Command, args []string) error {
2729 logrus .Error (err )
2830 return err
2931 }
32+ logger .SetupLogger ()
3033 service .InitServerService ()
3134 // if directory cannot be set correctly, following actions will panic
3235 return setupDirectory ()
Original file line number Diff line number Diff line change 1+ package logger
2+
3+ import (
4+ "os"
5+
6+ "github.com/sirupsen/logrus"
7+ )
8+
9+ func SetupLogger () {
10+ levelString := os .Getenv ("LOG" )
11+
12+ level , err := logrus .ParseLevel (levelString )
13+ if err != nil {
14+ logrus .SetLevel (logrus .InfoLevel )
15+ }
16+
17+ logrus .SetLevel (level )
18+ logrus .SetFormatter (& logrus.TextFormatter {
19+ ForceColors : true ,
20+ })
21+ }
You can’t perform that action at this time.
0 commit comments