...

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

Documentation: edge-infra.dev/pkg/lib/cli/clog

     1  package clog
     2  
     3  import (
     4  	"io"
     5  	"os"
     6  )
     7  
     8  type Option func(*options)
     9  
    10  // To allows setting the logging destination writer, defaults to `os.Stderr` if
    11  // not provided
    12  func To(dest io.Writer) Option {
    13  	return func(o *options) {
    14  		o.dest = dest
    15  	}
    16  }
    17  
    18  // WithLevel sets the verbosity level (V-level) for the created logr.Logger
    19  func WithLevel(lvl int) Option {
    20  	return func(o *options) {
    21  		o.lvl = lvl
    22  	}
    23  }
    24  
    25  // WithCaller configures which [MessageClass] logs get caller information.
    26  func WithCaller(c MessageClass) Option {
    27  	return func(o *options) {
    28  		o.logCaller = c
    29  	}
    30  }
    31  
    32  // private options struct, can only be changed by consumers via the public
    33  // Option function interface
    34  type options struct {
    35  	dest      io.Writer
    36  	lvl       int
    37  	logCaller MessageClass
    38  }
    39  
    40  func makeOptions(opts ...Option) options {
    41  	o := options{dest: os.Stderr, logCaller: Error}
    42  	for _, opt := range opts {
    43  		opt(&o)
    44  	}
    45  
    46  	return o
    47  }
    48  

View as plain text