@@ -51,11 +51,6 @@ high performance container runtime
5151`
5252
5353func init () {
54- logrus .SetFormatter (& logrus.TextFormatter {
55- TimestampFormat : log .RFC3339NanoFixed ,
56- FullTimestamp : true ,
57- })
58-
5954 // Discard grpc logs so that they don't mess with our stdio
6055 grpclog .SetLoggerV2 (grpclog .NewLoggerV2 (ioutil .Discard , ioutil .Discard , ioutil .Discard ))
6156
@@ -252,7 +247,10 @@ func serve(ctx gocontext.Context, l net.Listener, serveFunc func(net.Listener) e
252247func applyFlags (context * cli.Context , config * srvconfig.Config ) error {
253248 // the order for config vs flag values is that flags will always override
254249 // the config values if they are set
255- if err := setLevel (context , config ); err != nil {
250+ if err := setLogLevel (context , config ); err != nil {
251+ return err
252+ }
253+ if err := setLogFormat (config ); err != nil {
256254 return err
257255 }
258256 for _ , v := range []struct {
@@ -282,7 +280,7 @@ func applyFlags(context *cli.Context, config *srvconfig.Config) error {
282280 return nil
283281}
284282
285- func setLevel (context * cli.Context , config * srvconfig.Config ) error {
283+ func setLogLevel (context * cli.Context , config * srvconfig.Config ) error {
286284 l := context .GlobalString ("log-level" )
287285 if l == "" {
288286 l = config .Debug .Level
@@ -297,6 +295,29 @@ func setLevel(context *cli.Context, config *srvconfig.Config) error {
297295 return nil
298296}
299297
298+ func setLogFormat (config * srvconfig.Config ) error {
299+ f := config .Debug .Format
300+ if f == "" {
301+ f = log .TextFormat
302+ }
303+
304+ switch f {
305+ case log .TextFormat :
306+ logrus .SetFormatter (& logrus.TextFormatter {
307+ TimestampFormat : log .RFC3339NanoFixed ,
308+ FullTimestamp : true ,
309+ })
310+ case log .JSONFormat :
311+ logrus .SetFormatter (& logrus.JSONFormatter {
312+ TimestampFormat : log .RFC3339NanoFixed ,
313+ })
314+ default :
315+ return errors .Errorf ("unknown log format: %s" , f )
316+ }
317+
318+ return nil
319+ }
320+
300321func dumpStacks (writeToFile bool ) {
301322 var (
302323 buf []byte
0 commit comments