func main() { log := l4g.NewLogger() log.AddFilter("network", l4g.FINEST, l4g.NewSocketLogWriter("udp", "192.168.1.255:12124")) // Run `nc -u -l -p 12124` or similar before you run this to see the following message log.Info("The time is now: %s", time.Now().Format("15:04:05 MST 2006/01/02")) // This makes sure the output stream buffer is written log.Close() }
func NewAgent(opts Options) *Agent { log := l4g.NewLogger() log.AddFilter("file", l4g.DEBUG, l4g.NewFileLogWriter("agent.log", false)) return &Agent{ opts: opts, exitChan: make(chan bool), startTime: time.Now(), clients: make(map[*Client]struct{}, opts.MaxOnlineNum), Logger: log, } }
func main() { // Get a new logger instance log := l4g.NewLogger() // Create a default logger that is logging messages of FINE or higher log.AddFilter("file", l4g.FINE, l4g.NewFileLogWriter(filename, false)) log.Close() /* Can also specify manually via the following: (these are the defaults) */ flw := l4g.NewFileLogWriter(filename, false) flw.SetFormat("[%D %T] [%L] (%S) %M") flw.SetRotate(false) flw.SetRotateSize(0) flw.SetRotateLines(0) flw.SetRotateDaily(false) log.AddFilter("file", l4g.FINE, flw) // Log some experimental messages log.Finest("Everything is created now (notice that I will not be printing to the file)") log.Info("The time is now: %s", time.Now().Format("15:04:05 MST 2006/01/02")) log.Critical("Time to close out!") // Close the log log.Close() // Print what was logged to the file (yes, I know I'm skipping error checking) fd, _ := os.Open(filename) in := bufio.NewReader(fd) fmt.Print("Messages logged to file were: (line numbers not included)\n") for lineno := 1; ; lineno++ { line, err := in.ReadString('\n') if err == io.EOF { break } fmt.Printf("%3d:\t%s", lineno, line) } fd.Close() // Remove the file so it's not lying around os.Remove(filename) }
"bufio" "bytes" "encoding/base64" "encoding/json" "fmt" "io" "os" "strings" rdb "Grep/grep4r/rdb" log "code.google.com/p/log4go" // "github.com/wandoulabs/redis-port/pkg/libs/atomic2" ) var ( keyLog = log.NewLogger() keys = map[string]struct{}{} ) func init() { keyLog.AddFilter("log", log.FINE, log.NewFileLogWriter("keys-test", false)) } const ( ReaderBufferSize = 1024 * 1024 * 32 WriterBufferSize = 1024 * 1024 * 8 ) func parserRDBFile(input string, rdbsize uint64) { var readin io.ReadCloser
package main import ( log "code.google.com/p/log4go" "fmt" "os" "strconv" "strings" "time" ) var ( checkpoint = make(chan int64, 1) cpLog = log.NewLogger() CP_FILE_NAME = "checkpoint" cplen = len("[2015/12/24 17:38:47 CST] [INFO] (mongodb-driver/grep4m.writecp:106) 6231782484598587392") ) type deamon_timer struct { timer *time.Timer d time.Duration } func newDeamonTimer(d time.Duration) *deamon_timer { dtimer := new(deamon_timer) dtimer.timer = time.NewTimer(d) dtimer.d = d return dtimer }
func main() { log := l4g.NewLogger() defer log.Close() log.AddFilter("stdout", l4g.DEBUG, l4g.NewConsoleLogWriter()) log.Info("The time is now: %s", time.Now().Format("15:04:05 MST 2006/01/02")) }
func main() { logger := log4go.NewLogger() logger.Info("Test") }
func init() { log = l4g.NewLogger() }