Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

change log format

  • Loading branch information...
commit d43f437d46b14e554d5e223cc3ed6ea27d83d12e 1 parent a86d822
@mountain authored
Showing with 14 additions and 11 deletions.
  1. +5 −6 app/redirect.js
  2. +2 −4 vendor/node-router.js
  3. +7 −1 vendor/server.js
View
11 app/redirect.js
@@ -7,7 +7,6 @@ exports.app = function(env) {
admin = env.admin,
msg = env.i18n.msg;
-
return function(req, res, lang, title) {
var lang = lang || 'en',
pageId = parseInt(title.toLowerCase(), 36),
@@ -17,8 +16,8 @@ exports.app = function(env) {
if(url) {
res.redirect(url);
- sys.puts('cache get: (' + lang + ':' + pageId + ')');
- sys.puts('cache stats: (hits ' + cache.stats.hits + ', misses ' + cache.stats.misses + ')');
+ env.logger('cache get: (' + lang + ':' + pageId + ')');
+ env.logger('cache stats: (hits ' + cache.stats.hits + ', misses ' + cache.stats.misses + ')');
} else {
var http = require('http'),
wp = http.createClient(80, host),
@@ -46,12 +45,12 @@ exports.app = function(env) {
}
}
} catch (e) {
- sys.puts('error when parsing json: ' + e);
+ env.logger('error when parsing json: ' + e);
}
if(url) {
cache.setItem(lang + ':' + pageId, url);
- sys.puts('cache put: (' + lang + ':' + pageId + ')');
- sys.puts('cache stats: (hits ' + cache.stats.hits + ', misses ' + cache.stats.misses + ')');
+ env.logger('cache put: (' + lang + ':' + pageId + ')');
+ env.logger('cache stats: (hits ' + cache.stats.hits + ', misses ' + cache.stats.misses + ')');
res.redirect(url);
} else {
var dir = util.htmlDir(env, lang);
View
6 vendor/node-router.js
@@ -46,10 +46,9 @@ function logify(req, res, logger) {
var end = res.end;
res.end = function () {
// Common Log Format (mostly)
- logger((req.socket && req.socket.remoteAddress) + " - - [" + (new Date()).toUTCString() + "]"
- + " \"" + req.method + " " + req.url
+ logger((req.socket && req.socket.remoteAddress) + " - \"" + req.method + " " + req.url
+ " HTTP/" + req.httpVersionMajor + "." + req.httpVersionMinor + "\" "
- + res.statusCode + " - \""
+ + " - " + res.statusCode + " - \""
+ (req.headers['referer'] || "") + "\" \"" + (req.headers["user-agent"] ? req.headers["user-agent"].split(' ')[0] : '') + "\"");
return end.apply(this, arguments);
}
@@ -536,4 +535,3 @@ var mime = exports.mime = {
".zip" : "application/zip"
}
};
-
View
8 vendor/server.js
@@ -1,4 +1,5 @@
var _ = require('../lib/underscore')._,
+ sys = require('sys'),
router = require('./node-router'),
i18n = require('../config/i18n').i18n,
routers = require('../config/routers').routers;
@@ -23,10 +24,15 @@ exports.start = function(settings) {
var cacheSize = env.cacheSize || 1000;
env.cache = new (require('../lib/cache').Cache)(cacheSize);
+ env.logger = (function() {
+ sys.print((new Date()).toUTCString() + " - ");
+ sys.puts(_.toArray(arguments).join(" "));
+ });
+
require('./template').load(env);
setTimeout(function() {
- var server = router.getServer();
+ var server = router.getServer(env.logger);
_(routers).chain().keys().each(function(key) {
server.get(routers[key], require('../app/' + key).app(env));
Please sign in to comment.
Something went wrong with that request. Please try again.