Documentation ¶
Overview ¶
Package cmd implements cmd helpers.
This provides helpers on top of `github.com/urfave/cli`.
Example usage:
var c *cli.Context // Get this from your action log, err := cmd.NewLogger(c) if err != nil { // Handle error. } stats, err := cmd.NewStatter(c, log) if err != nil { // Handle error. }
Index ¶
- Constants
- Variables
- func NewLogger(c *cli.Context) (*logger.Logger, error)
- func NewProfiler(c *cli.Context, svc string, log *logger.Logger) (*pyroscope.Profiler, error)
- func NewStatter(c *cli.Context, log *logger.Logger, opts ...statter.Option) (*statter.Statter, error)
- func NewTracer(c *cli.Context, log *logger.Logger, resAttributes ...attribute.KeyValue) (*trace.TracerProvider, error)
- func Split(slice []string, sep string) ([][2]string, error)
- type Flags
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'.", EnvVars: []string{"LOG_FORMAT"}, }, &cli.StringFlag{ Name: FlagLogLevel, Category: CategoryLog, Value: "info", Usage: "Specify the log level. e.g. 'trace', 'debug', 'info', 'error'.", EnvVars: []string{"LOG_LEVEL"}, }, &cli.StringSliceFlag{ Name: FlagLogCtx, Category: CategoryLog, Usage: "A list of context field appended to every log. Format: key=value.", EnvVars: []string{"LOG_CTX"}, }, }
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'.", EnvVars: []string{"PROFILING_DSN"}, }, &cli.DurationFlag{ Name: FlagProfileUploadRate, Category: CategoryProfiling, Usage: "The rate at which profiles are uploaded.", Value: 15 * time.Second, EnvVars: []string{"PROFILING_UPLOAD_RATE"}, }, &cli.StringSliceFlag{ Name: FlagProfilingTags, Category: CategoryProfiling, Usage: "A list of tags appended to every profile. Format: key=value.", EnvVars: []string{"PROFILING_TAGS"}, }, &cli.StringSliceFlag{ Name: FlagProfilingTypes, Category: CategoryProfiling, Usage: "The type of profiles to include. Defaults to all.", EnvVars: []string{"PROFILING_TYPES"}, }, }
ProfilingFlags are flags that configure profiling.
var StatsFlags = Flags{ &cli.StringFlag{ Name: FlagStatsDSN, Category: CategoryStats, Usage: "The DSN of a stats backend.", EnvVars: []string{"STATS_DSN"}, }, &cli.DurationFlag{ Name: FlagStatsInterval, Category: CategoryStats, Usage: "The frequency at which the stats are reported.", Value: time.Second, EnvVars: []string{"STATS_INTERVAL"}, }, &cli.StringFlag{ Name: FlagStatsPrefix, Category: CategoryStats, Usage: "The prefix of the measurements names.", EnvVars: []string{"STATS_PREFIX"}, }, &cli.StringSliceFlag{ Name: FlagStatsTags, Category: CategoryStats, Usage: "A list of tags appended to every measurement. Format: key=value.", EnvVars: []string{"STATS_TAGS"}, }, }
StatsFlags are flags that configure stats.
var TracingFlags = Flags{ &cli.StringFlag{ Name: FlagTracingExporter, Category: CategoryTracing, Usage: "The tracing backend. Supported: 'zipkin', 'otlphttp', 'otlpgrpc'.", EnvVars: []string{"TRACING_EXPORTER"}, }, &cli.StringFlag{ Name: FlagTracingEndpoint, Category: CategoryTracing, Usage: "The tracing backend endpoint.", EnvVars: []string{"TRACING_ENDPOINT"}, }, &cli.BoolFlag{ Name: FlagTracingEndpointInsecure, Category: CategoryTracing, Usage: "Determines if the endpoint is insecure.", EnvVars: []string{"TRACING_ENDPOINT_INSECURE"}, }, &cli.StringSliceFlag{ Name: FlagTracingTags, Category: CategoryTracing, Usage: "A list of tags appended to every trace. Format: key=value.", EnvVars: []string{"TRACING_TAGS"}, }, &cli.StringSliceFlag{ Name: FlagTracingHeaders, Category: CategoryTracing, Usage: "A list of headers appended to every trace when supported by the exporter. Format: key=value.", EnvVars: []string{"TRACING_HEADERS"}, }, &cli.Float64Flag{ Name: FlagTracingRatio, Category: CategoryTracing, Usage: "The ratio between 0 and 1 of sample traces to take.", Value: 0.5, EnvVars: []string{"TRACING_RATIO"}, }, }
TracingFlags are flags that configure tracing.
Functions ¶
func NewLogger ¶
func NewLogger(c *cli.Context) (*logger.Logger, error)
NewLogger returns a logger configured from the cli.
Example ¶
var c *cli.Context // Get this from your action log, err := cmd.NewLogger(c) if err != nil { // Handle error. return } _ = log
Output:
func NewProfiler ¶ added in v2.10.0
NewProfiler returns a profiler configured from the cli. If no profiler is configured, nil is returned.
Example ¶
var c *cli.Context // 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
Output:
func NewStatter ¶
func NewStatter(c *cli.Context, log *logger.Logger, opts ...statter.Option) (*statter.Statter, error)
NewStatter returns a statter configured from the cli.
Example ¶
var c *cli.Context // 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 stats.Close() _ = stats
Output:
func NewTracer ¶
func NewTracer(c *cli.Context, log *logger.Logger, resAttributes ...attribute.KeyValue) (*trace.TracerProvider, error)
NewTracer returns a tracer configured from the cli.
Example ¶
var c *cli.Context // Get this from your action log, err := cmd.NewLogger(c) if err != nil { // Handle error. return } tracer, err := cmd.NewTracer(c, log, semconv.ServiceNameKey.String("my-service"), semconv.ServiceVersionKey.String("1.0.0"), ) if err != nil { // Handle error. return } defer tracer.Shutdown(context.Background()) _ = tracer
Output:
Types ¶
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. |