Skip to content

Commit 226ff72

Browse files
joeybloggsjoeybloggs
authored andcommitted
Add HipChat log handler
- Added some goods for all handlers. - Updated all handlers to have a buffer of 3 and 3 workers by default.
1 parent 5b7ff90 commit 226ff72

File tree

12 files changed

+684
-21
lines changed

12 files changed

+684
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## log
22
<img align="right" src="https://raw.githubusercontent.com/go-playground/log/master/logo.png">
3-
![Project status](https://img.shields.io/badge/version-3.0.1-green.svg)
3+
![Project status](https://img.shields.io/badge/version-3.1.0-green.svg)
44
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/log/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/log)
55
[![Coverage Status](https://coveralls.io/repos/github/go-playground/log/badge.svg?branch=master)](https://coveralls.io/github/go-playground/log?branch=master)
66
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/log)](https://goreportcard.com/report/github.com/go-playground/log)

handlers/console/console.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ var defaultColors = [...]log.ANSIEscSeq{
5959
// New returns a new instance of the console logger
6060
func New() *Console {
6161
return &Console{
62-
buffer: 0,
63-
numWorkers: 1,
62+
buffer: 3,
63+
numWorkers: 3,
6464
colors: defaultColors,
6565
writer: os.Stderr,
6666
timestampFormat: log.DefaultTimeFormat,

handlers/console/doc.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Package console allows for log messages to be sent to a any writer, default os.Stderr.
3+
4+
Example
5+
6+
simple console
7+
8+
package main
9+
10+
import (
11+
"github.com/go-playground/log"
12+
"github.com/go-playground/log/handlers/console"
13+
)
14+
15+
func main() {
16+
17+
cLog := console.New()
18+
19+
log.RegisterHandler(cLog, log.AllLevels...)
20+
21+
// Trace
22+
defer log.Trace("trace").End()
23+
24+
log.Debug("debug")
25+
log.Info("info")
26+
log.Notice("notice")
27+
log.Warn("warn")
28+
log.Error("error")
29+
// log.Panic("panic") // this will panic
30+
log.Alert("alert")
31+
// log.Fatal("fatal") // this will call os.Exit(1)
32+
33+
// logging with fields can be used with any of the above
34+
log.WithFields(log.F("key", "value")).Info("test info")
35+
}
36+
*/
37+
package console

handlers/email/doc.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Package email allows for log messages to be sent via email.
3+
4+
Example
5+
6+
simple email
7+
8+
package main
9+
10+
import (
11+
"github.com/go-playground/log"
12+
"github.com/go-playground/log/handlers/email"
13+
)
14+
15+
func main() {
16+
17+
email := email.New("smtp.gmail.com", 587, "username", "password", "[email protected]", []string{"[email protected]"})
18+
email.SetFilenameDisplay(log.Llongfile)
19+
20+
log.RegisterHandler(email, log.WarnLevel, log.AlertLevel, log.PanicLevel)
21+
22+
log.WithFields(log.F("error", "something went wrong")).StackTrace().Alert("ALERT!")
23+
}
24+
*/
25+
package email

handlers/email/email.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ type Email struct {
6565
func New(host string, port int, username string, password string, from string, to []string) *Email {
6666

6767
return &Email{
68-
buffer: 0,
69-
numWorkers: 1,
68+
buffer: 3,
69+
numWorkers: 3,
7070
timestampFormat: log.DefaultTimeFormat,
7171
fileDisplay: log.Lshortfile,
7272
templateHTML: defaultTemplate,

handlers/http/doc.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Package http allows for log messages to be sent via http.
3+
4+
Example
5+
6+
NOTE: you can use the HTTP handler as a base for creating other handlers
7+
8+
package main
9+
10+
import (
11+
stdhttp "net/http"
12+
13+
"github.com/go-playground/log"
14+
"github.com/go-playground/log/handlers/http"
15+
)
16+
17+
func main() {
18+
19+
header := make(stdhttp.Header)
20+
header.Set("Authorization", "Bearer 378978HJJFEWj73JENEWFN3475")
21+
22+
h, err := http.New("https://logs.logserver.com:4565", "POST", header)
23+
if err != nil {
24+
// handle error, most likely URL parsing error
25+
}
26+
27+
h.SetFilenameDisplay(log.Llongfile)
28+
29+
log.RegisterHandler(h, log.AllLevels...)
30+
31+
// Trace
32+
defer log.Trace("trace").End()
33+
34+
log.Debug("debug")
35+
log.Info("info")
36+
log.Notice("notice")
37+
log.Warn("warn")
38+
log.Error("error")
39+
// log.Panic("panic") // this will panic
40+
log.Alert("alert")
41+
// log.Fatal("fatal") // this will call os.Exit(1)
42+
43+
// logging with fields can be used with any of the above
44+
log.WithFields(log.F("key", "value")).Info("test info")
45+
}
46+
*/
47+
package http

handlers/http/hipchat/doc.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Package hipchat allows for log messages to be sent to a hipchat room.
3+
4+
Example
5+
6+
NOTE: "/notification" is added to the host url automatically.
7+
8+
package main
9+
10+
import (
11+
"github.com/go-playground/log"
12+
"github.com/go-playground/log/handlers/http/hipchat"
13+
)
14+
15+
func main() {
16+
17+
// NOTE: ROOM TOKEN must have view permissions for room
18+
hc, err := hipchat.New(hipchat.APIv2, "https://api.hipchat.com/v2/room/{ROOM ID or NAME}", "application/json", "{ROOM TOKEN}")
19+
if err != nil {
20+
log.Error(err)
21+
}
22+
hc.SetFilenameDisplay(log.Llongfile)
23+
24+
log.RegisterHandler(hc, log.WarnLevel, log.AlertLevel, log.PanicLevel)
25+
26+
log.WithFields(log.F("error", "something went wrong")).StackTrace().Alert("ALERT!")
27+
}
28+
*/
29+
package hipchat

0 commit comments

Comments
 (0)