From b658c4360685e816bc0b21e567ffd16724571dcb Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 1 Oct 2017 11:44:21 +0200 Subject: log files --- .gitignore | 2 ++ app.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b56c7b9..df5ce31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ md md/ node_modules/ +node.access.log +node.error.log diff --git a/app.js b/app.js index efb2989..8a4313b 100644 --- a/app.js +++ b/app.js @@ -9,6 +9,12 @@ const converter = new showdown.Converter(); const app = express(); const path = 'md'; +const access = fs.createWriteStream('node.access.log', {flags: 'a'}); +const error = fs.createWriteStream('node.error.log', {flags: 'a'}); + +process.stdout.write = access.write.bind(access); +process.stderr.write = error.write.bind(error); + converter.setOption('parseImgDimensions', 'true'); converter.setOption('literalMidWordUnderscores', 'true'); converter.setOption('literalMidWordAsterisks', 'true'); @@ -19,6 +25,7 @@ converter.setOption('tasklists', 'true'); app.use(express.static('public')); app.get('/' + path + '/*', function(req, res) { + console.log("200 - " + req.url); fs.readFile(req.url.substr(1), 'utf8', function(err, data) { if (err) return console.log(err); @@ -27,16 +34,19 @@ app.get('/' + path + '/*', function(req, res) { }); app.get('/data', function(req, res) { + console.log("200 - " + req.url); res.send(dirTree(path, {extensions:/\.md/})); }); app.get('/img/*', function (req, res) { + console.log("200 - " + req.url); var img = fs.readFileSync(req.url.replace('/img', path)); res.writeHead(200, {'Content-Type': 'image/gif' }); res.end(img, 'binary'); }); app.get('/', function(req, res) { + console.log("200 - " + req.url); fs.readFile('public/index.html', 'utf8', function(err, data) { if (err) return console.log(err); @@ -45,7 +55,7 @@ app.get('/', function(req, res) { }); app.get('*', function(req, res) { - console.log("404 - " + req.url); + console.error("404 - " + req.url); fs.readFile('public/404.md', 'utf8', function(err, data) { if (err) return console.log(err); -- cgit v1.2.3