Created
November 15, 2013 21:29
-
-
Save mratzloff/7491951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} | |
} |
Author
mratzloff
commented
Nov 15, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment