Documentation ¶
Overview ¶
Package logdflag provides a standard flag set for configuring the logger package and starting logging. Typical usage would be something like:
import( "bitbucket.org/pcas/logger/logd/logdflag" "bitbucket.org/pcastools/flag" ... )
// parseArgs parses the command-line flags and environment variables.
func parseArgs() error { // Define the usage message and command-line flags flag.SetGlobalHeader(fmt.Sprintf("...header for the usage message...") flag.SetName("Options") flag.Add( flag.String("foo", ...), ... ) // Add the flagset that controls the logger logSet := logdflag.NewLogSet(nil) flag.AddSet(logSet) // Parse the flags flag.Parse() // Do any additional sanity checks ... // Set the global logger, using the application name as the log name if err := logdflag.SetLogger( logSet.ToStderr(), logSet.ToServer(), logSet.ClientConfig(), Name, ); err != nil { return err } return nil }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultIdentifier ¶
func DefaultIdentifier() string
DefaultIdentifier returns the identifier set on the logd client. This is typically of the form "<hostname>-<PID>", however if the hostname cannot be determined then a ULID is used.
func SetLogger ¶
func SetLogger(ctx context.Context, toStderr bool, toServer bool, c *logd.ClientConfig, name string) error
SetLogger sets the global logger log.Log() as specified by toStderr, toServer, the client config c, and the destination log name. This will also update the default client config to c. If necessary, a shutdown function will be registered with package "bitbucket.org/pcastools/cleanup".
Types ¶
type LogSet ¶
type LogSet struct { *Set // contains filtered or unexported fields }
LogSet represents a set of command-line flags defined by a client config, and provides destination logging information.
func NewLogSet ¶
func NewLogSet(c *logd.ClientConfig) *LogSet
NewLogSet returns a set of command-line flags as described by NewSet. In addition, this set provides destination logging information.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set represents a set of command-line flags defined by a client config.
func NewSet ¶
func NewSet(c *logd.ClientConfig) *Set
NewSet returns a set of command-line flags with defaults given by c. If c is nil then the logd.DefaultConfig() will be used. Note that this does not update the default client config, nor does this update c. To recover the updated client config after parse, call the ClientConfig() method on the returned set.
func (*Set) ClientConfig ¶
func (s *Set) ClientConfig() *logd.ClientConfig
ClientConfig returns the client config described by this set. This should only be called after the set has been successfully validated.
func (*Set) UsageFooter ¶
UsageFooter returns the footer for the usage message for this flag set.
func (*Set) UsageHeader ¶
UsageHeader returns the header for the usage message for this flag set.