diff options
author | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
commit | cf7a05f80f68b5b1c8bcc0089679dd497cec2506 (patch) | |
tree | 70007378570a6962d7c175ca96af732b71aeb6da /Godeps/_workspace/src/code.google.com/p/log4go/examples | |
download | chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.tar.gz chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.tar.bz2 chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.zip |
first commit
Diffstat (limited to 'Godeps/_workspace/src/code.google.com/p/log4go/examples')
6 files changed, 190 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/code.google.com/p/log4go/examples/ConsoleLogWriter_Manual.go b/Godeps/_workspace/src/code.google.com/p/log4go/examples/ConsoleLogWriter_Manual.go new file mode 100644 index 000000000..394ca8380 --- /dev/null +++ b/Godeps/_workspace/src/code.google.com/p/log4go/examples/ConsoleLogWriter_Manual.go @@ -0,0 +1,13 @@ +package main + +import ( + "time" +) + +import l4g "code.google.com/p/log4go" + +func main() { + log := l4g.NewLogger() + log.AddFilter("stdout", l4g.DEBUG, l4g.NewConsoleLogWriter()) + log.Info("The time is now: %s", time.Now().Format("15:04:05 MST 2006/01/02")) +} diff --git a/Godeps/_workspace/src/code.google.com/p/log4go/examples/FileLogWriter_Manual.go b/Godeps/_workspace/src/code.google.com/p/log4go/examples/FileLogWriter_Manual.go new file mode 100644 index 000000000..efd596aa6 --- /dev/null +++ b/Godeps/_workspace/src/code.google.com/p/log4go/examples/FileLogWriter_Manual.go @@ -0,0 +1,57 @@ +package main + +import ( + "bufio" + "fmt" + "io" + "os" + "time" +) + +import l4g "code.google.com/p/log4go" + +const ( + filename = "flw.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) +} diff --git a/Godeps/_workspace/src/code.google.com/p/log4go/examples/SimpleNetLogServer.go b/Godeps/_workspace/src/code.google.com/p/log4go/examples/SimpleNetLogServer.go new file mode 100644 index 000000000..83c80ad12 --- /dev/null +++ b/Godeps/_workspace/src/code.google.com/p/log4go/examples/SimpleNetLogServer.go @@ -0,0 +1,42 @@ +package main + +import ( + "flag" + "fmt" + "net" + "os" +) + +var ( + port = flag.String("p", "12124", "Port number to listen on") +) + +func e(err error) { + if err != nil { + fmt.Printf("Erroring out: %s\n", err) + os.Exit(1) + } +} + +func main() { + flag.Parse() + + // Bind to the port + bind, err := net.ResolveUDPAddr("0.0.0.0:" + *port) + e(err) + + // Create listener + listener, err := net.ListenUDP("udp", bind) + e(err) + + fmt.Printf("Listening to port %s...\n", *port) + for { + // read into a new buffer + buffer := make([]byte, 1024) + _, _, err := listener.ReadFrom(buffer) + e(err) + + // log to standard output + fmt.Println(string(buffer)) + } +} diff --git a/Godeps/_workspace/src/code.google.com/p/log4go/examples/SocketLogWriter_Manual.go b/Godeps/_workspace/src/code.google.com/p/log4go/examples/SocketLogWriter_Manual.go new file mode 100644 index 000000000..400b698ca --- /dev/null +++ b/Godeps/_workspace/src/code.google.com/p/log4go/examples/SocketLogWriter_Manual.go @@ -0,0 +1,18 @@ +package main + +import ( + "time" +) + +import l4g "code.google.com/p/log4go" + +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() +} diff --git a/Godeps/_workspace/src/code.google.com/p/log4go/examples/XMLConfigurationExample.go b/Godeps/_workspace/src/code.google.com/p/log4go/examples/XMLConfigurationExample.go new file mode 100644 index 000000000..164c2add4 --- /dev/null +++ b/Godeps/_workspace/src/code.google.com/p/log4go/examples/XMLConfigurationExample.go @@ -0,0 +1,13 @@ +package main + +import l4g "code.google.com/p/log4go" + +func main() { + // Load the configuration (isn't this easy?) + l4g.LoadConfiguration("example.xml") + + // And now we're ready! + l4g.Finest("This will only go to those of you really cool UDP kids! If you change enabled=true.") + l4g.Debug("Oh no! %d + %d = %d!", 2, 2, 2+2) + l4g.Info("About that time, eh chaps?") +} diff --git a/Godeps/_workspace/src/code.google.com/p/log4go/examples/example.xml b/Godeps/_workspace/src/code.google.com/p/log4go/examples/example.xml new file mode 100644 index 000000000..e791278ce --- /dev/null +++ b/Godeps/_workspace/src/code.google.com/p/log4go/examples/example.xml @@ -0,0 +1,47 @@ +<logging> + <filter enabled="true"> + <tag>stdout</tag> + <type>console</type> + <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> + <level>DEBUG</level> + </filter> + <filter enabled="true"> + <tag>file</tag> + <type>file</type> + <level>FINEST</level> + <property name="filename">test.log</property> + <!-- + %T - Time (15:04:05 MST) + %t - Time (15:04) + %D - Date (2006/01/02) + %d - Date (01/02/06) + %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) + %S - Source + %M - Message + It ignores unknown format strings (and removes them) + Recommended: "[%D %T] [%L] (%S) %M" + --> + <property name="format">[%D %T] [%L] (%S) %M</property> + <property name="rotate">false</property> <!-- true enables log rotation, otherwise append --> + <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> + <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> + <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> + </filter> + <filter enabled="true"> + <tag>xmllog</tag> + <type>xml</type> + <level>TRACE</level> + <property name="filename">trace.xml</property> + <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> + <property name="maxsize">100M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> + <property name="maxrecords">6K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> + <property name="daily">false</property> <!-- Automatically rotates when a log message is written after midnight --> + </filter> + <filter enabled="false"><!-- enabled=false means this logger won't actually be created --> + <tag>donotopen</tag> + <type>socket</type> + <level>FINEST</level> + <property name="endpoint">192.168.1.255:12124</property> <!-- recommend UDP broadcast --> + <property name="protocol">udp</property> <!-- tcp or udp --> + </filter> +</logging> |