https://github.com/clcert/golang-http-logger
:writing_hand:HTTP logger middleware for Go
https://github.com/clcert/golang-http-logger
Last synced: 5 months ago
JSON representation
:writing_hand:HTTP logger middleware for Go
- Host: GitHub
- URL: https://github.com/clcert/golang-http-logger
- Owner: clcert
- License: mit
- Fork: true (go-http-utils/logger)
- Created: 2022-09-22T23:15:32.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-09-22T23:47:22.000Z (over 3 years ago)
- Last Synced: 2024-06-20T13:39:13.950Z (almost 2 years ago)
- Language: Go
- Homepage: https://godoc.org/github.com/go-http-utils/logger
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# logger
[](https://travis-ci.org/go-http-utils/logger)
[](https://coveralls.io/github/go-http-utils/logger?branch=master)
HTTP logger middleware for Go
## Modifications
A little change has been made, filtering the log of static requests.
## Installation
```sh
go get -u github.com/clcert/golang-http-logger
```
## Documentation
https://godoc.org/github.com/go-http-utils/logger
## Usage
```go
import (
"net/http"
"os"
"github.com/clcert/golang-http-logger"
)
mux := http.NewServeMux()
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte("Hello World"))
})
http.ListenAndServe(":8080", logger.Handler(mux, os.Stdout, logger.DevLoggerType))
```
## Supportted log output format
### CombineLoggerType
CombineLoggerType is the standard Apache combined log output
```
:remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"
```
### CommonLoggerType
CommonLoggerType is the standard Apache common log output
```
:remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length]
```
### DevLoggerType
DevLoggerType is useful for development
```
:method :url :status :response-time ms - :res[content-length]
```
### ShortLoggerType
ShortLoggerType is shorter than common, including response time
```
:remote-addr :remote-user :method :url HTTP/:http-version :status :res[content-length] - :response-time ms
```
### TinyLoggerType
TinyLoggerType is the minimal ouput
```
:method :url :status :res[content-length] - :response-time ms
```