Skip to content

Commit 1e5bd14

Browse files
committed
feat(router): improve log output.
1 parent 3efd001 commit 1e5bd14

4 files changed

Lines changed: 26 additions & 1 deletion

File tree

router/parent/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ RUN DOCKER_BUILD=true /go/src/github.com/deis/deis/router/build.sh
99
RUN tar -C /opt/nginx -czf /nginx.tgz .
1010

1111
ADD boot.go /go/src/github.com/deis/deis/router/boot.go
12+
ADD logger/stdout_formatter.go /go/src/github.com/deis/deis/router/logger/stdout_formatter.go
1213

1314
RUN go get
1415

router/parent/boot.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"github.com/ActiveState/tail"
1414
"github.com/Sirupsen/logrus"
1515
"github.com/coreos/go-etcd/etcd"
16+
17+
"github.com/deis/deis/router/logger"
1618
)
1719

1820
var log = logrus.New()
@@ -26,6 +28,8 @@ const (
2628
)
2729

2830
func main() {
31+
log.Formatter = new(logger.StdOutFormatter)
32+
2933
logLevel := getopt("LOG", "info")
3034
if level, err := logrus.ParseLevel(logLevel); err == nil {
3135
log.Level = level
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package logger
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
"strings"
7+
8+
"github.com/Sirupsen/logrus"
9+
)
10+
11+
type StdOutFormatter struct {
12+
}
13+
14+
func (f *StdOutFormatter) Format(entry *logrus.Entry) ([]byte, error) {
15+
b := &bytes.Buffer{}
16+
fmt.Fprintf(b, "[%s] - %s\n", strings.ToUpper(entry.Level.String()), entry.Message)
17+
return b.Bytes(), nil
18+
}

router/templates/nginx.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ http {
3333
{{ end }}
3434
client_max_body_size {{ or (.deis_router_bodySize) "1m" }};
3535

36+
log_format upstreaminfo '[$time_local] - $remote_addr - $remote_user - $status - "$request" - $bytes_sent - "$http_referer" - "$http_user_agent" - "$server_name" - $upstream_addr';
37+
3638
# send logs to STDOUT so they can be seen using 'docker logs'
37-
access_log /opt/nginx/logs/access.log;
39+
access_log /opt/nginx/logs/access.log upstreaminfo;
3840
error_log /opt/nginx/logs/error.log;
3941

4042
map $http_upgrade $connection_upgrade {

0 commit comments

Comments
 (0)