git ssb

30+

cel / git-ssb-web



Commit 5fd4aa9b06699a4902c338327f26c760c9225157

Use log levels. Log http requests beneath default log level

Charles Lehner committed on 4/25/2016, 1:17:27 AM
Parent: 99befd1748ff5af4fca65ee3f111f8f71d5d12d3

Files changed

index.jschanged
index.jsView
@@ -104,8 +104,10 @@
104104 this.ssb = ssb
105105 this.config = config
106106 this.reconnect = reconnect
107107
108+ if (config.logging && config.logging.level)
109+ this.logLevel = this.logLevels.indexOf(config.logging.level)
108110 this.ssbAppname = config.appname || 'ssb'
109111 this.isPublic = config.public
110112 this.getVotes = require('./lib/votes')(ssb)
111113 this.getMsg = asyncMemo(ssb.get)
@@ -137,14 +139,22 @@
137139 }
138140
139141 var G = GitSSBWeb.prototype
140142
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+
141151 G.listen = function (host, port) {
142152 this.httpServer = http.createServer(G_onRequest.bind(this))
143153 this.httpServer.listen(port, host, function () {
144154 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))
147157 }
148158
149159 G.getRepoName = function (ownerId, repoId, cb) {
150160 this.about.getName({
@@ -191,9 +201,9 @@
191201 )
192202 }
193203
194204 function G_onRequest(req, res) {
195- console.log(req.method, req.url)
205+ this.log('info', req.method, req.url)
196206 req._u = url.parse(req.url, true)
197207 var locale = req._u.query.locale ||
198208 (/locale=([^;]*)/.exec(req.headers.cookie) || [])[1]
199209 var reqLocales = req.headers['accept-language']

Built with git-ssb-web