...

Source file src/edge-infra.dev/pkg/lib/fog/options.go

Documentation: edge-infra.dev/pkg/lib/fog

     1  package fog
     2  
     3  import (
     4  	"io"
     5  	"os"
     6  )
     7  
     8  // To allows setting the logging destination writer, defaults to `os.Stdout` if
     9  // not provided
    10  func To(dest io.Writer) Option {
    11  	return func(o *options) {
    12  		o.dest = dest
    13  	}
    14  }
    15  
    16  // WithLevel sets the verbosity level for the created logger. Passing any negative
    17  // value will disable non-Error() logs by setting Zap's log level to Error (2).
    18  func WithLevel(lvl int) Option {
    19  	return func(o *options) {
    20  		if lvl < 0 {
    21  			lvl = 2
    22  		}
    23  		o.lvl = int8(toZapLevel(lvl))
    24  	}
    25  }
    26  
    27  // private options struct, can only be changed by consumers via the public
    28  // Option function interface
    29  type options struct {
    30  	dest        io.Writer
    31  	lvl         int8
    32  	development bool
    33  }
    34  
    35  func makeOptions(opts ...Option) options {
    36  	o := options{dest: os.Stdout, development: false}
    37  	for _, opt := range opts {
    38  		opt(&o)
    39  	}
    40  
    41  	return o
    42  }
    43  
    44  // setDevelopment sets the boolean to true so that Zap's development mode can be used
    45  func setDevelopment() Option {
    46  	return func(o *options) {
    47  		o.development = true
    48  	}
    49  }
    50  

View as plain text