Permalink
Browse files

Added rudimentary log viewer

  • Loading branch information...
1 parent b7ffb06 commit 540a7aebdcf8288ed091baf25525ae43ab9903fe @hectorcorrea committed Sep 8, 2012
Showing with 67 additions and 2 deletions.
  1. +3 −0 app.coffee
  2. +9 −0 logs/2012_08_06.txt
  3. +23 −0 logs/2012_09_08.txt
  4. +25 −0 routes/logRoutes.coffee
  5. +7 −2 util/logger.coffee
View
@@ -4,6 +4,7 @@ ejs = require 'ejs'
{Logger} = require './util/logger'
siteRoutes = require './routes/siteRoutes'
blogRoutes = require './routes/blogRoutes'
+logRoutes = require './routes/logRoutes'
app = module.exports = express.createServer()
@@ -66,6 +67,8 @@ app.get '/blog', blogRoutes.viewRecent
app.get '/blog/:topicUrl', blogRoutes.viewOne
+app.get '/logs/current', logRoutes.current
+
app.get '*', siteRoutes.notFound
# Fire it up!
View
@@ -20,3 +20,12 @@
2012-08-06 10:10:10.077 INFO: blogRoutes:viewRecent
2012-08-06 10:10:10.430 INFO: blogRoutes:viewOne beyond-hello-world-with-node-js-express-js-and-coffeescript
2012-08-06 10:10:10.948 INFO: blogRoutes:edit beyond-hello-world-with-node-js-express-js-and-coffeescript
+2012-08-06 10:33:33.016 INFO: Express server listening on http://localhost:3000 in development mode
+2012-08-06 10:34:34.729 INFO: Express server listening on http://localhost:3000 in development mode
+2012-08-06 10:34:34.802 INFO: Express server listening on http://localhost:3000 in development mode
+2012-08-06 10:35:35.408 INFO: Express server listening on http://localhost:3000 in development mode
+2012-08-06 10:37:37.907 INFO: Express server listening on http://localhost:3000 in development mode
+2012-08-06 10:39:39.682 INFO: blogRoutes:viewRecent
+2012-08-06 10:39:39.630 INFO: blogRoutes:viewOne a-decaf-introduction-to-coffeescript
+2012-08-06 10:39:39.321 INFO: blogRoutes:viewRecent
+2012-08-06 10:39:39.378 INFO: blogRoutes:viewOne javascript-async-programming-for-sync-heads
View
@@ -0,0 +1,23 @@
+1 2012-09-08 10:51:51.417 INFO: Express server listening on http://localhost:3000 in development mode
+2 2012-09-08 10:51:51.303 INFO: blogRoutes:viewOne javascript-async-programming-for-sync-heads
+1 2012-09-08 10:56:56.264 INFO: Express server listening on http://localhost:3000 in development mode
+1 2012-09-08 10:57:57.683 INFO: Express server listening on http://localhost:3000 in development mode
+2 2012-09-08 10:58:58.750 INFO: blogRoutes:viewRecent
+3 2012-09-08 10:58:58.650 INFO: blogRoutes:viewRecent
+4 2012-09-08 10:58:58.661 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+5 2012-09-08 10:58:58.695 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+6 2012-09-08 10:58:58.891 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+7 2012-09-08 10:58:58.075 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+8 2012-09-08 10:58:58.285 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+9 2012-09-08 10:58:58.467 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+10 2012-09-08 10:58:58.733 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+11 2012-09-08 10:58:58.878 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+12 2012-09-08 10:58:58.921 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+13 2012-09-08 10:58:58.101 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+14 2012-09-08 10:58:58.317 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+15 2012-09-08 10:58:58.499 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+16 2012-09-08 10:58:58.626 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+17 2012-09-08 10:58:58.821 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+18 2012-09-08 10:58:58.050 INFO: blogRoutes:viewOne web-development-on-the-mac-os-x-(part-ii)
+19 2012-09-08 10:59:59.343 INFO: blogRoutes:viewRecent
+20 2012-09-08 10:59:59.896 INFO: blogRoutes:viewOne javascript-async-programming-for-sync-heads
View
@@ -0,0 +1,25 @@
+fs = require 'fs'
+{Logger} = require '../util/logger'
+
+current = (req, res) ->
+
+ logFile = Logger.currentLogFile()
+ fs.readFile logFile, (err, text) ->
+ if err
+ html = "<html><body>"
+ html += "<p>Could not read log file <b>#{logFile}</b></p>"
+ html += "<p>#{err}</p>"
+ html += "</body></html>"
+ res.send html, 500
+ else
+ res.send text, { 'Content-Type': 'text/plain' }, 200
+
+one = (req, res) ->
+ # todo: implement code to view one specific log file
+
+list = (req, res) ->
+ # todo: implement code to view a list of log files
+
+module.exports = {
+ current: current
+}
View
@@ -4,8 +4,8 @@ class Logger
@_logLevel = 'INFO'
- @_logPath = './logs/'
- @_logFile = ''
+ @_logPath = './logs/' # set up null to prevent log to text file
+ @_logFile = '' # calculated in _getTimestamp()
@_pad: (number, zeroes) =>
@@ -75,6 +75,11 @@ class Logger
text = text + "\r\n#{exception}" if exception?
@_doLog 'ERROR', "#{text}"
+ @currentLogFile: =>
+ return null if @_logPath is null
+ # Make sure @_logFile has been set
+ @_getTimestamp()
+ return @_logPath + @_logFile
exports.Logger = Logger

0 comments on commit 540a7ae

Please sign in to comment.