Permalink
Browse files

Updated log viewer to use Express 3.x syntax and display the error lo…

…g in an HTML friendly format
  • Loading branch information...
1 parent 9974f77 commit 7c1251d71f313923865a5de1876ab5d6b34ff2db @hectorcorrea committed Sep 10, 2012
Showing with 60 additions and 13 deletions.
  1. +46 −0 logs/2012_09_09.txt
  2. +1 −1 package.json
  3. +11 −12 routes/logRoutes.coffee
  4. +2 −0 util/logger.coffee
View
@@ -139,3 +139,49 @@
2012-09-09 21:54:54.438 INFO: blogRoutes:viewRecent
2012-09-09 21:54:54.537 INFO: blogRoutes:viewOne beyond-hello-world-xxx
2012-09-09 21:54:54.789 INFO: blogRoutes:viewRecent
+2012-09-09 22:05:05.971 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:15:15.212 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:16:16.033 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:17:17.725 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:17:17.516 INFO: logRoutes.viewCurrent
+2012-09-09 22:17:17.049 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:18:18.458 INFO: logRoutes.viewCurrent
+2012-09-09 22:26:26.587 INFO: logRoutes.viewCurrent
+2012-09-09 22:26:26.952 INFO: logRoutes.viewCurrent
+2012-09-09 22:26:26.778 INFO: logRoutes.viewCurrent
+2012-09-09 22:26:26.654 INFO: logRoutes.viewCurrent
+2012-09-09 22:28:28.244 INFO: blogRoutes:rssList
+2012-09-09 22:29:29.536 INFO: blogRoutes:rssList
+2012-09-09 22:29:29.393 INFO: blogRoutes:rssList
+2012-09-09 22:42:42.265 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:42:42.713 INFO: logRoutes.viewCurrent
+2012-09-09 22:43:43.775 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:43:43.592 INFO: logRoutes.viewCurrent
+2012-09-09 22:43:43.661 INFO: logRoutes.viewCurrent
+2012-09-09 22:43:43.991 INFO: logRoutes.viewCurrent
+2012-09-09 22:44:44.061 INFO: logRoutes.viewCurrent
+2012-09-09 22:44:44.896 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:45:45.567 INFO: logRoutes.viewCurrent
+2012-09-09 22:45:45.325 INFO: logRoutes.viewCurrent
+2012-09-09 22:52:52.890 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:52:52.825 INFO: logRoutes.viewCurrent
+2012-09-09 22:53:53.623 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:53:53.901 INFO: logRoutes.viewCurrent
+2012-09-09 22:53:53.650 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:53:53.271 INFO: logRoutes.viewCurrent
+2012-09-09 22:53:53.305 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:53:53.030 INFO: logRoutes.viewCurrent
+2012-09-09 22:54:54.251 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:54:54.810 INFO: logRoutes.viewCurrent
+2012-09-09 22:55:55.313 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:55:55.136 INFO: logRoutes.viewCurrent
+2012-09-09 22:56:56.414 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 22:56:56.841 INFO: logRoutes.viewCurrent
+2012-09-09 23:01:01.797 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 23:01:01.449 INFO: logRoutes.viewCurrent
+2012-09-09 23:01:01.456 ERROR: logRoutes.viewSpecific: Error reading log file ./logs/2012_09_09.txt
+null
+2012-09-09 23:01:01.626 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 23:01:01.373 INFO: logRoutes.viewCurrent
+2012-09-09 23:01:01.374 ERROR: logRoutes.viewSpecific: Error reading log file ./logs/2012_09_09.txt
+null
View
@@ -1,6 +1,6 @@
{
"name": "simple-blog",
- "version": "0.0.1-7",
+ "version": "0.0.1-8",
"private": true,
"dependencies": {
"express": "= 3.0.0rc4",
View
@@ -21,36 +21,35 @@ _isValidLogDate = (text) ->
return false
+#TODO: This code should use streams rather than reading the
+# entire log file to memory.
viewCurrent = (req, res) ->
logFile = Logger.currentLogFile()
+ Logger.info 'logRoutes.viewCurrent'
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
+ Logger.error "logRoutes.viewSpecific: Error reading log file #{logFile}\r\n#{err}"
+ res.render '500', {status: 500, message: "Could not read log file: #{logFile}"}
else
- res.send text, { 'Content-Type': 'text/plain' }, 200
+ text = text.toString().replace(/\r\n/g, '<br/>')
+ res.send text
viewSpecific = (req, res) ->
logDate = req.params.logDate
if _isValidLogDate logDate
+ Logger.info 'logRoutes.viewSpecific #{logDate}'
logDate = logDate.replace(/-/g, '_')
logFile = './logs/' + logDate + '.txt'
fs.readFile logFile, (err, text) ->
if err
Logger.error "logRoutes.viewSpecific: Error reading log file #{logFile}\r\n#{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
+ res.render '500', {status: 500, message: "Could not read log file: #{logFile}"}
else
- res.send text, { 'Content-Type': 'text/plain' }, 200
+ text = text.replace(/\r\n/g, '<br/>')
+ res.send text
else
Logger.error "logRoutes.viewSpecific: Invalid log date received #{logDate}"
res.redirect '/'
View
@@ -75,11 +75,13 @@ 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 7c1251d

Please sign in to comment.