mclogs

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2023 License: MIT Imports: 10 Imported by: 0

README

mclogs

Github Action Version Go Report Card

mclogs is a fake log generator, heavily inspired on flog ❤️, with a wink to McDonald's, and support for common log formats json and logfmt.

It is useful for testing some tasks which require log data like amazon kinesis log stream test.

Thanks to gofakeit and weightedrand 😘

Installation

Using go get
go get -u github.com/joanlopez/mclogs
Using .tar.gz archive

Download gzip file from Github Releases according to your OS. Then, copy the unzipped executable to under system path.

Using Docker
docker run -it --rm ghcr.io/joanlopez/mclogs

Usage

There are useful options. (mclogs --help)

Options:
  -f, --format string      log format - available formats:
                           - json (default)
                           - logfmt
  -o, --output string      output filename (default "stdout") - path-like is allowed 
  -n, --number integer     number of lines to generate (default "100")
  -b, --bytes integer      size of logs to generate (in bytes)
                           "bytes" will be ignored when "number" is set
  -s, --sleep duration     fix creation time interval for each log (default unit "seconds") - it does not actually sleep
                           examples: 10, 20ms, 5s, 1m
  -d, --delay duration     delay log generation speed (default unit "seconds")
                           examples: 10, 20ms, 5s, 1m
  -a, --at date            date and time -RFC3339- the log generation starts at (default "now")
                           examples: 2023-01-01T15:00:00+02:00
  -w, --overwrite          overwrite the existing log files
  -l, --loop               loop output forever until killed
# Generate 100 lines of logs to stdout
$ mclogs

# Generate 200 lines of logs with a time interval of 10s for each log. It doesn't actually sleep while generating
$ mclogs -s 10s -n 200 

# Generate a log file with 1000 lines of logs, then overwrite existing log file
$ mclogs -n 1000 -o generated.log -w

Supported Formats

  • JSON
  • Logfmt

Supported Outputs

  • Stdout
  • File

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FormatJSON   = Format("json")
	FormatLogfmt = Format("logfmt")
)
View Source
var ErrFormatNotSupported = errors.New("format not supported")

Functions

func Generate

func Generate(cfg Config) error

Generate generates the logs with given configuration.

func NewLog

func NewLog(format Format, at time.Time) string

NewLog creates a log for given format.

func Run

func Run(cfg Config) error

Run checks overwrite flag and generates logs with given configuration.

Types

type Config

type Config struct {
	Format    Format
	Output    string
	Lines     int
	Bytes     int
	Sleep     time.Duration
	Delay     time.Duration
	At        time.Time
	Overwrite bool
	Forever   bool
}

func DefaultConfig

func DefaultConfig() Config

type CustomerOrder

type CustomerOrder struct {
	Name        string
	HasAccount  bool
	TotalAmount float64
	At          time.Time
}

func (CustomerOrder) Format

func (co CustomerOrder) Format(f Format) string

type CustomerSatisfaction

type CustomerSatisfaction struct {
	Name              string
	HasAccount        bool
	SatisfactionLevel int
	At                time.Time
}

func (CustomerSatisfaction) Format

func (cs CustomerSatisfaction) Format(f Format) string

type Event

type Event interface {
	Format(Format) string
}

func NewCustomerOrder

func NewCustomerOrder(at time.Time) Event

func NewCustomerSatisfaction

func NewCustomerSatisfaction(at time.Time) Event

func NewEvent

func NewEvent(at time.Time) Event

type Format

type Format string

func NewFormat

func NewFormat(f string) (Format, error)

func (Format) String

func (f Format) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL