Commit 5fd4aa9b06699a4902c338327f26c760c9225157
Use log levels. Log http requests beneath default log level
Charles Lehner committed on 4/25/2016, 1:17:27 AMParent: 99befd1748ff5af4fca65ee3f111f8f71d5d12d3
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -104,8 +104,10 @@ | ||
104 | 104 | this.ssb = ssb |
105 | 105 | this.config = config |
106 | 106 | this.reconnect = reconnect |
107 | 107 | |
108 | + if (config.logging && config.logging.level) | |
109 | + this.logLevel = this.logLevels.indexOf(config.logging.level) | |
108 | 110 | this.ssbAppname = config.appname || 'ssb' |
109 | 111 | this.isPublic = config.public |
110 | 112 | this.getVotes = require('./lib/votes')(ssb) |
111 | 113 | this.getMsg = asyncMemo(ssb.get) |
@@ -137,14 +139,22 @@ | ||
137 | 139 | } |
138 | 140 | |
139 | 141 | var G = GitSSBWeb.prototype |
140 | 142 | |
143 | +G.logLevels = ['error', 'warning', 'notice', 'info'] | |
144 | +G.logLevel = G.logLevels.indexOf('notice') | |
145 | + | |
146 | +G.log = function (level) { | |
147 | + if (this.logLevels.indexOf(level) > this.logLevel) return | |
148 | + console.log.apply(console, [].slice.call(arguments, 1)) | |
149 | +} | |
150 | + | |
141 | 151 | G.listen = function (host, port) { |
142 | 152 | this.httpServer = http.createServer(G_onRequest.bind(this)) |
143 | 153 | this.httpServer.listen(port, host, function () { |
144 | 154 | var hostName = ~host.indexOf(':') ? '[' + host + ']' : host |
145 | - console.log('Listening on http://' + hostName + ':' + port + '/') | |
146 | - }) | |
155 | + this.log('notice', 'Listening on http://' + hostName + ':' + port + '/') | |
156 | + }.bind(this)) | |
147 | 157 | } |
148 | 158 | |
149 | 159 | G.getRepoName = function (ownerId, repoId, cb) { |
150 | 160 | this.about.getName({ |
@@ -191,9 +201,9 @@ | ||
191 | 201 | ) |
192 | 202 | } |
193 | 203 | |
194 | 204 | function G_onRequest(req, res) { |
195 | - console.log(req.method, req.url) | |
205 | + this.log('info', req.method, req.url) | |
196 | 206 | req._u = url.parse(req.url, true) |
197 | 207 | var locale = req._u.query.locale || |
198 | 208 | (/locale=([^;]*)/.exec(req.headers.cookie) || [])[1] |
199 | 209 | var reqLocales = req.headers['accept-language'] |
Built with git-ssb-web