https://github.com/meowgorithm/babylogger
A Go HTTP logger middleware, for babies
https://github.com/meowgorithm/babylogger
go goji logging middleware
Last synced: 2 months ago
JSON representation
A Go HTTP logger middleware, for babies
- Host: GitHub
- URL: https://github.com/meowgorithm/babylogger
- Owner: meowgorithm
- License: mit
- Created: 2018-05-17T18:31:12.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-06-01T14:20:45.000Z (almost 2 years ago)
- Last Synced: 2025-02-28T07:51:39.150Z (3 months ago)
- Topics: go, goji, logging, middleware
- Language: Go
- Homepage: https://godoc.org/github.com/meowgorithm/babylogger
- Size: 30.3 KB
- Stars: 15
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Babylogger
==========[](https://pkg.go.dev/github.com/meowgorithm/babylogger)
A Go HTTP logger middleware, for babies.

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 mainimport (
"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