File: README.md

package info (click to toggle)
golang-github-meowgorithm-babylogger 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 92 kB
  • sloc: makefile: 3
file content (75 lines) | stat: -rw-r--r-- 1,665 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Babylogger
==========

[![GoDoc Badge](https://godoc.org/github.com/magicnumbers/babylogger?status.svg)](https://pkg.go.dev/github.com/meowgorithm/babylogger)

A Go HTTP logger middleware, for babies.

![Example image of Babylogger doing its logging](https://i.imgur.com/VGg7Wl6.png "Babylogger doing its logging")

We’ve used it with [Goji][goji] and the Go standard library, but it should work
with any multiplexer worth its salt. And by that we mean any multiplexer
compatible with the standard library.

Note that ANSI escape sequences (read: colors) will be stripped from the output
when the logger is not running in a terminal. For example, log files won't
contain any sort of ANSI intended for color output.

Also note that for accurate response time logging Babylogger should be the first middleware
called.


## Examples

### Standard Library

```go
package main

import (
    "fmt"
    "net/http"
    "github.com/magicnumbers/babylogger"
)

func main() {
    http.Handle("/", babylogger.Middleware(http.HandlerFunc(handler)))
    http.ListenAndServe(":8000", nil)
}

handler(w http.ResponseWriter, r *http.Request) {
    fmt.FPrintln(w, "Oh, hi, I didn’t see you there.")
}
```

### Goji

```go

import (
    "fmt"
    "net/http"
    "github.com/magicnumbers/babylogger"
    "goji.io"
    "goji.io/pat"
)

func main() {
    mux := goji.NewMux()
    mux.Use(babylogger.Middleware)
    mux.HandleFunc(pat.Get("/"), handler)
    http.ListenAndServe(":8000", mux)
}

handler(w http.ResponseWriter, r *http.Request) {
    fmt.FPrintln(w, "Oh hi, I didn’t see you there.")
}
```


## License

MIT

[goji]: http://goji.io
[mattn]: https://github.com/mattn