blob: de9168a3420603489ddcb2a5d7db602b324ab8c4 (
plain)
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
|
package echo
import (
"io"
"os"
"github.com/labstack/echo/v4/middleware"
)
const (
nginxCombinedHostFormat = `${host} ${remote_ip} - - [${time_custom}] "${method} ${uri} ` +
`${protocol}" ${status} ${bytes_out} "${referer}" "${user_agent}"` + "\n"
nginxCombinedHostDateFormat = "02/Jan/2006:15:04:04 -0700"
)
func NginxCombinedHostConfig(o io.Writer) middleware.LoggerConfig {
return middleware.LoggerConfig{
Format: nginxCombinedHostFormat,
CustomTimeFormat: nginxCombinedHostDateFormat,
Output: o,
}
}
// TODO: Implement HUP as re-open (like: https://github.com/client9/reopen/blob/master/reopen.go)
func NginxCombinedHostConfigToFile(f string) (middleware.LoggerConfig, error) {
o, err := os.OpenFile(f, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err != nil {
return middleware.LoggerConfig{}, err
}
return NginxCombinedHostConfig(o), nil
}
|