Skip to content

Commit

Permalink
Merge pull request #140 from jrwren/001-add-access-log
Browse files Browse the repository at this point in the history
add http access log
  • Loading branch information
jujugui authored Jul 1, 2016
2 parents b853069 + e42f529 commit 6186e43
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/jemd/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ identity-location: http://localhost:8081/
# agent-key: {private: VnTcdjEOBBBjHNJ9knRtMA0I1PCATNySJXhW4PGE5hY=, public: MusIzFaXa7ImSMcQ9wgGpaDrgRQhbtsjsyawTvmXh1c=}
# For production identity manager (jemd will collect the correct public key on startup).
#identity-location: https://api.jujucharms.com/identity
access-log: /var/log/jem/access.log
14 changes: 13 additions & 1 deletion cmd/jemd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"strings"

"github.com/gorilla/handlers"
// Include any providers known to support JEM.
// Avoid including provider/all to reduce build time.
_ "github.com/juju/juju/provider/ec2"
Expand All @@ -21,6 +22,7 @@ import (
"gopkg.in/macaroon-bakery.v1/bakery"
"gopkg.in/macaroon-bakery.v1/httpbakery"
"gopkg.in/mgo.v2"
"gopkg.in/natefinch/lumberjack.v2"

"github.com/CanonicalLtd/jem"
"github.com/CanonicalLtd/jem/config"
Expand Down Expand Up @@ -96,7 +98,17 @@ func serve(confPath string) error {
if err != nil {
return errgo.Notef(err, "cannot create new server at %q", conf.APIAddr)
}
handler := server.(http.Handler)
if conf.AccessLog != "" {
accesslog := &lumberjack.Logger{
Filename: conf.AccessLog,
MaxSize: 500, // megabytes
MaxBackups: 3,
MaxAge: 28, //days
}
handler = handlers.CombinedLoggingHandler(accesslog, handler)
}

logger.Infof("starting the API server")
return http.ListenAndServe(conf.APIAddr, server)
return http.ListenAndServe(conf.APIAddr, handler)
}
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config struct {
IdentityLocation string `yaml:"identity-location"`
AgentUsername string `yaml:"agent-username"`
AgentKey *bakery.KeyPair `yaml:"agent-key"`
AccessLog string `yaml:"access-log"`
}

func (c *Config) validate() error {
Expand Down
1 change: 1 addition & 0 deletions dependencies.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ github.com/coreos/go-systemd git 7b2428fec40033549c68f54e26e89e7ca9a9ce31 2016-0
github.com/dustin/go-humanize git 145fabdb1ab757076a70a886d092a3af27f66f4c 2014-12-28T07:11:48Z
github.com/godbus/dbus git 32c6cc29c14570de4cf6d7e7737d68fb2d01ad15 2016-05-06T22:25:50Z
github.com/golang/groupcache git 604ed5785183e59ae2789449d89e73f3a2a77987 2015-01-25T18:08:32Z
github.com/gorilla/handlers git a24b39a6a2c8a7af2fe664dd4573205c99904035 2015-04-12T18:40:04Z
github.com/gorilla/schema git 08023a0215e7fc27a9aecd8b8c50913c40019478 2016-04-26T23:15:12Z
github.com/gorilla/websocket git 13e4d0621caa4d77fd9aa470ef6d7ab63d1a5e41 2015-09-23T22:29:30Z
github.com/juju/bundlechanges git 8d99dd2a94d7b4fd975a152238d0e19d0c4a6cf1 2016-06-15T07:19:43Z
Expand Down

0 comments on commit 6186e43

Please sign in to comment.