Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions lib/glog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var path = require('path'),
async = require('async'),
config = require('config');

// Custom log package
var log = require('glogger')('GLOG');

/*
* Setup module
Expand Down Expand Up @@ -61,8 +63,6 @@ Glog.prototype.load_configs = function(cb) {
options[key] = config[key];
}

console.log(JSON.stringify(options));

cb(options);

}
Expand Down Expand Up @@ -102,8 +102,8 @@ Glog.prototype.load_plugins = function(options, cb) {
var p = require('../plugins/' + options.plugins[i]);
p.load(GlogPlugin);
} catch(e) {
console.log('Error loading plugins');
console.log(e);
log.info('Error loading plugins');
log.info(e);
}
}

Expand All @@ -120,7 +120,7 @@ Glog.prototype.load_articles = function(options, cb) {
article_path = path.join('blog_repo', '/articles'),
fn = this;

console.log('Loading articles from ' + article_path);
log.info('Loading articles from ' + article_path);

fs.readdir(article_path, function(err, files) {
if(err) {
Expand All @@ -130,14 +130,14 @@ Glog.prototype.load_articles = function(options, cb) {
// Remove incorrect extensions
for(var i=0; i<files.length; i++) {
if(path.extname(files[i]) !== '.txt' && path.extname(files[i]) !== '.md') {
console.log('Skipping file ' + files[i] + ' Incorrect extension');
log.info('Skipping file ' + files[i] + ' Incorrect extension');
files.splice(i,1);
}
}


for(var i=0; i<files.length; i++) {
console.log('Reading file ' + files[i]);
log.info('Reading file ' + files[i]);

fs.readFile(path.join(article_path, files[i]), 'UTF-8', function(err, data) {
if(err) {
Expand All @@ -150,8 +150,8 @@ Glog.prototype.load_articles = function(options, cb) {
parts.splice(0,1);
var body = parts.join('\n\n');

console.log('Read articles with headers: ');
console.log(header);
log.info('Read articles with headers: ');
log.info(JSON.stringify(header));

// Check mandatory fields
if(!header.title) {
Expand Down Expand Up @@ -193,7 +193,7 @@ Glog.prototype.load_articles = function(options, cb) {
var postlength = Number(fn.articlePostPlugins.length);
var prelength = Number(fn.articlePrePlugins.length);
if(fn.articlePrePlugins.length > 1){
console.log('preplugins');
log.info('preplugins');
fn.articlePrePlugins[0] = function(wcb){
wcb(null, articles);
}
Expand Down Expand Up @@ -296,7 +296,7 @@ Glog.prototype.render_blog = function(options, articles, cb) {
fn.handle_error('Error loading layout. Err: ' + err);
}

console.log('Compiling template for home page');
log.info('Compiling template for home page');
var ja = jade.compile(data),
per_page = options.articles_per_page,
i, len = Math.floor((articles.length / per_page) + 1),
Expand All @@ -319,7 +319,7 @@ Glog.prototype.render_blog = function(options, articles, cb) {
fn.pages['/'] = fn.pages['_page1'];
}

console.log('Compiling template for individual pages');
log.info('Compiling template for individual pages');

// Loop through articles and compile individual pages
for(var i=0; i< articles.length; i++) {
Expand All @@ -344,11 +344,11 @@ Glog.prototype.render_blog = function(options, articles, cb) {
* Handle a request for the home page
*/
Glog.prototype.req_home = function(req, res, next, options) {
console.log('Home page requested');
log.info('Home page requested');

var pagenum = req.params.pagenum || 1;

console.log('Rendering page ' + pagenum);
log.info('Rendering page ' + pagenum);

// Set headers
res.setHeader('Content-Type', 'text/html; charset=utf-8');
Expand All @@ -367,7 +367,7 @@ Glog.prototype.req_home = function(req, res, next, options) {
* Handle a request for the RSS feed
*/
Glog.prototype.req_rss = function(req, res, next, options) {
console.log('RSS feed requested');
log.info('RSS feed requested');

// Set headers
res.setHeader('Content-Type', 'application/rss+xml; charset=utf-8');
Expand All @@ -386,7 +386,7 @@ Glog.prototype.req_article = function(req, res, next, options) {
var fn = this,
url = [req.params.year, req.params.month, req.params.article].join('/');

console.log('Requesting ' + url);
log.info('Requesting ' + url);
if(typeof this.pages[url] === 'undefined') {
// Set headers
res.setHeader('Content-Type', 'text/html; charset=utf-8');
Expand All @@ -407,7 +407,7 @@ Glog.prototype.req_article = function(req, res, next, options) {
* Generic error handler
*/
Glog.prototype.handle_error = function(err) {
console.error(err);
log.error(err);
}


Expand Down Expand Up @@ -443,14 +443,14 @@ Glog.prototype.get_repo = function(repo, cb) {
var fn = this;

// Attempt to clone the git repo
console.log('Cloning git repository ' + repo);
log.info('Cloning git repository ' + repo);
exec('git clone ' + repo + ' blog_repo', function(error, stdout, stderr) {
if(error) {
fn.handle_error('Could not clone git repository: ' + error);
cb(false);
}
console.log('Stdout: ' + stdout);
console.log('Stderr: ' + stderr);
log.info('Stdout: ' + stdout);
log.info('Stderr: ' + stderr);

cb(true);
});
Expand All @@ -474,14 +474,14 @@ Glog.prototype.update_repo = function(options, cb) {
fn.get_repo(options.blog_repository, cb);
} else {

console.log('Updating blog git repo');
log.info('Updating blog git repo');
exec('cd blog_repo; git pull origin master', function(error, stdout, stderr) {
if(err) {
fn.handle_error('Could not update blog repo: ' + error);
cb(false);
}
console.log('Stdout: ' + stdout);
console.log('Stderr: ' + stderr);
log.info('Stdout: ' + stdout);
log.info('Stderr: ' + stderr);

cb(true);
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"mocha": ">= 0.8.2",
"rss": ">= 0.0.3",
"async": ">= 0.1.22",
"config": "~0.4.17"
"config": "~0.4.17",
"gloggler" : "git://github.com/guyht/glogger.git"
},
"devDependencies": {
"underscore": "~1.4.2"
Expand Down
8 changes: 6 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ var glog = require('./lib/glog'),
express = require('express'),
path = require('path');

// Custom log package
var log = require('glogger')('SERVER');


glog.rebuild(function() {
glog.load_configs(function(options) {

console.log('Starting server on port ' + options.port);
log.info('Starting server on port ' + options.port);

var server = express.createServer(
express.static(path.join('blog_repo', '/public')),
express.staticCache(),
express.logger({'format': 'tiny', 'stream': log.stream()}),
express.router(function(app) {
app.get('/__render', function(req, res, next) {
glog.rebuild(function() {
Expand Down Expand Up @@ -38,6 +42,6 @@ glog.rebuild(function() {
glog.req_home(req, res, next, options)
});
})
).listen(options.port);
).listen(process.env.VCAP_APP_PORT || options.port);
});
});