add an option to skip timestamps every now and then.

master
Jordan Orelli 11 years ago
parent da2154ebbc
commit 1b94bd1d30

@ -23,6 +23,7 @@ var (
ftruncate bool // whether or not to truncate file on open
pidfile string // path of pidfile to write out
reopen bool // whether or not to reopen the file handle on every line write
nots float64 // odds of generating a line without a timestamp. Should be between 0 and 1.
tsformat string // timestamp format
lineLength lengthArg // length of the lines to be generated
ts func() string // function to get a timestamp string
@ -298,7 +299,23 @@ func flags() (err error) {
if dictionary != "" {
readDict(dictionary)
}
ts = mkTsFn()
tmp := mkTsFn()
tsLen := len(tmp())
blank := make([]byte, tsLen)
for i := range blank {
blank[i] = ' '
}
whitespace := string(blank)
if nots > 0 {
ts = func() string {
if rand.Float64() < nots {
return whitespace
}
return tmp()
}
} else {
ts = tmp
}
line, err = lineLength.mkLineFn()
return
}
@ -321,6 +338,7 @@ func main() {
func init() {
flag.StringVar(&fname, "file", "", "destination file to which random data will be written")
flag.StringVar(&tsformat, "ts-format", "", "timestamp format")
flag.Float64Var(&nots, "no-ts", 0.0, "odds of generating a line without a timestamp")
flag.StringVar(&pidfile, "pidfile", "", "file to which a pid is written")
flag.BoolVar(&ftruncate, "truncate", false, "truncate file on opening instead of appending")
flag.StringVar(&dictionary, "dict", "", "dictionary of words to use for generating log data")

Loading…
Cancel
Save