Documentation
¶
Overview ¶
Package cmd implements cmd helpers.
This provides helpers on top of `github.com/urfave/cli`.
Index ¶
- Constants
- Variables
- func NewLogger(cmd *cli.Command) (*logger.Logger, error)
- func NewLoggerWithOptions(cmd *cli.Command, opts *LoggerOptions) (*logger.Logger, error)
- func NewProfiler(cmd *cli.Command, svc string, log *logger.Logger) (*pyroscope.Profiler, error)
- func NewStatter(cmd *cli.Command, log *logger.Logger, opts ...statter.Option) (*statter.Statter, error)
- func NewTracer(ctx context.Context, cmd *cli.Command, log *logger.Logger, ...) (*trace.TracerProvider, error)
- type Flags
- type LoggerOptions
Examples ¶
Constants ¶
const ( FlagLogFormat = "log.format" FlagLogLevel = "log.level" FlagLogCtx = "log.ctx" )
Log flag constants declared for CLI use.
const ( FlagProfilingDSN = "profiling.dsn" FlagProfileUploadRate = "profiling.upload-rate" FlagProfilingTags = "profiling.tags" FlagProfilingTypes = "profiling.types" )
Tracing flag constants declared for CLI use.
const ( FlagStatsDSN = "stats.dsn" FlagStatsInterval = "stats.interval" FlagStatsPrefix = "stats.prefix" FlagStatsTags = "stats.tags" )
Stats flag constants declared for CLI use.
const ( FlagTracingExporter = "tracing.exporter" FlagTracingEndpoint = "tracing.endpoint" FlagTracingEndpointInsecure = "tracing.endpoint-insecure" FlagTracingTags = "tracing.tags" FlagTracingHeaders = "tracing.headers" FlagTracingRatio = "tracing.ratio" )
Tracing flag constants declared for CLI use.
const CategoryLog = "Logging"
CategoryLog is the log flag category.
const CategoryProfiling = "Profiling"
CategoryProfiling is the profiling category.
const CategoryStats = "Stats"
CategoryStats is the stats flag category.
const CategoryTracing = "Tracing"
CategoryTracing is the tracing flag category.
Variables ¶
var LogFlags = Flags{ &cli.StringFlag{ Name: FlagLogFormat, Category: CategoryLog, Usage: "Specify the format of logs. Supported formats: 'logfmt', 'json', 'console'", Sources: cli.EnvVars(strcase.ToSNAKE(FlagLogFormat)), }, &cli.StringFlag{ Name: FlagLogLevel, Category: CategoryLog, Value: "info", Usage: "Specify the log level. e.g. 'debug', 'info', 'error'.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagLogLevel)), }, &cli.StringMapFlag{ Name: FlagLogCtx, Category: CategoryLog, Usage: "A list of context field appended to every log. Format: key=value.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagLogCtx)), }, }
LogFlags are flags that configure logging.
var MonitoringFlags = Flags{}.Merge(LogFlags, StatsFlags, ProfilingFlags, TracingFlags)
MonitoringFlags are flags that configure logging, stats, profiling and tracing.
var ProfilingFlags = Flags{ &cli.StringFlag{ Name: FlagProfilingDSN, Category: CategoryProfiling, Usage: "The address to the Pyroscope server, in the format: " + "'http://basic:auth@server:port?token=auth-token&tenantid=tenant-id'.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagProfilingDSN)), }, &cli.DurationFlag{ Name: FlagProfileUploadRate, Category: CategoryProfiling, Usage: "The rate at which profiles are uploaded.", Value: 15 * time.Second, Sources: cli.EnvVars(strcase.ToSNAKE(FlagProfileUploadRate)), }, &cli.StringMapFlag{ Name: FlagProfilingTags, Category: CategoryProfiling, Usage: "A list of tags appended to every profile.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagProfilingTags)), }, &cli.StringSliceFlag{ Name: FlagProfilingTypes, Category: CategoryProfiling, Usage: "The type of profiles to include. Defaults to all.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagProfilingTypes)), }, }
ProfilingFlags are flags that configure profiling.
var StatsFlags = Flags{ &cli.StringFlag{ Name: FlagStatsDSN, Category: CategoryStats, Usage: "The DSN of a stats backend.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagStatsDSN)), }, &cli.DurationFlag{ Name: FlagStatsInterval, Category: CategoryStats, Usage: "The frequency at which the stats are reported.", Value: defaultStatsInterval, Sources: cli.EnvVars(strcase.ToSNAKE(FlagStatsInterval)), }, &cli.StringFlag{ Name: FlagStatsPrefix, Category: CategoryStats, Usage: "The prefix of the measurements names.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagStatsPrefix)), }, &cli.StringMapFlag{ Name: FlagStatsTags, Category: CategoryStats, Usage: "A list of tags appended to every measurement.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagStatsTags)), }, }
StatsFlags are flags that configure stats.
var TracingFlags = Flags{ &cli.StringFlag{ Name: FlagTracingExporter, Category: CategoryTracing, Usage: "The tracing backend. Supported: 'zipkin', 'otlphttp', 'otlpgrpc'.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagTracingExporter)), }, &cli.StringFlag{ Name: FlagTracingEndpoint, Category: CategoryTracing, Usage: "The tracing backend endpoint.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagTracingEndpoint)), }, &cli.BoolFlag{ Name: FlagTracingEndpointInsecure, Category: CategoryTracing, Usage: "Determines if the endpoint is insecure.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagTracingEndpointInsecure)), }, &cli.StringMapFlag{ Name: FlagTracingTags, Category: CategoryTracing, Usage: "A list of tags appended to every trace.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagTracingTags)), }, &cli.StringMapFlag{ Name: FlagTracingHeaders, Category: CategoryTracing, Usage: "A list of headers appended to every trace when supported by the exporter.", Sources: cli.EnvVars(strcase.ToSNAKE(FlagTracingHeaders)), }, &cli.FloatFlag{ Name: FlagTracingRatio, Category: CategoryTracing, Usage: "The ratio between 0 and 1 of sample traces to take.", Value: 0.5, Sources: cli.EnvVars(strcase.ToSNAKE(FlagTracingRatio)), }, }
TracingFlags are flags that configure tracing.
Functions ¶
func NewLogger ¶
func NewLogger(cmd *cli.Command) (*logger.Logger, error)
NewLogger returns a logger configured from the cli.
Example ¶
var c *cli.Command // Get this from your action log, err := cmd.NewLogger(c) if err != nil { // Handle error. return } _ = log
func NewLoggerWithOptions ¶
func NewLoggerWithOptions(cmd *cli.Command, opts *LoggerOptions) (*logger.Logger, error)
NewLoggerWithOptions returns a logger configured from the cli.
func NewProfiler ¶
NewProfiler returns a profiler configured from the cli. If no profiler is configured, nil is returned.
Example ¶
var c *cli.Command // Get this from your action log, err := cmd.NewLogger(c) if err != nil { // Handle error. return } prof, err := cmd.NewProfiler(c, "my-service", log) if err != nil { // Handle error. return } if prof != nil { defer func() { _ = prof.Stop() }() } _ = prof
func NewStatter ¶
func NewStatter(cmd *cli.Command, log *logger.Logger, opts ...statter.Option) (*statter.Statter, error)
NewStatter returns a statter configured from the cli.
Example ¶
var c *cli.Command // Get this from your action log, err := cmd.NewLogger(c) if err != nil { // Handle error. return } stats, err := cmd.NewStatter(c, log) if err != nil { // Handle error. return } defer func() { _ = stats.Close() }() _ = stats
func NewTracer ¶
func NewTracer(ctx context.Context, cmd *cli.Command, log *logger.Logger, attrs ...attribute.KeyValue) (*trace.TracerProvider, error)
NewTracer returns a tracer configured from the cli.
Example ¶
var ( ctx context.Context c *cli.Command // Get this from your action ) log, err := cmd.NewLogger(c) if err != nil { // Handle error. return } tracer, err := cmd.NewTracer(ctx, c, log, semconv.ServiceNameKey.String("my-service"), semconv.ServiceVersionKey.String("1.0.0"), ) if err != nil { // Handle error. return } defer func() { _ = tracer.Shutdown(context.Background()) }() _ = tracer
Types ¶
type LoggerOptions ¶
LoggerOptions are options for creating a logger.
Directories
¶
Path | Synopsis |
---|---|
Package observe implements a type that combines statter, logger and tracer.
|
Package observe implements a type that combines statter, logger and tracer. |
Package term implements a unified way to present output.
|
Package term implements a unified way to present output. |