Skip to content

Instantly share code, notes, and snippets.

@mratzloff
Created November 15, 2013 21:29
Show Gist options
  • Save mratzloff/7491951 to your computer and use it in GitHub Desktop.
Save mratzloff/7491951 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/rand"
"fmt"
log "github.com/cihub/seelog"
"io"
"os"
)
const lines = 100000
var chars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
func main() {
logger, err := log.LoggerFromConfigAsString(`
<seelog>
<outputs formatid="common">
<filter levels="info,warn,error,critical">
<file path="/tmp/seelog-44.log" />
</filter>
</outputs>
<formats>
<format id="common" format="%Date %Time%t[%LEVEL]%t%Msg%n" />
</formats>
</seelog>
`)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
defer logger.Flush()
for i := 0; i < lines; i++ {
logger.Info(randomString(256))
}
fmt.Printf("lines: %d\n", lines)
}
// Shamelessly stolen from github.com/dchest/uniuri
func randomString(length int) string {
b := make([]byte, length)
r := make([]byte, length+(length/4)) // storage for random bytes.
clen := byte(len(chars))
maxrb := byte(256 - (256 % len(chars)))
i := 0
for {
if _, err := io.ReadFull(rand.Reader, r); err != nil {
panic("error reading from random source: " + err.Error())
}
for _, c := range r {
if c >= maxrb {
continue
}
b[i] = chars[c%clen]
i++
if i == length {
return string(b)
}
}
}
}
@mratzloff
Copy link
Author

#!/bin/sh

$GOPATH/bin/example &
$GOPATH/bin/example &
$GOPATH/bin/example &
$GOPATH/bin/example &

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment