Skip to content

Commit

Permalink
more support on winston logger in this application
Browse files Browse the repository at this point in the history
  • Loading branch information
mike820324 committed Mar 5, 2015
1 parent 1b80f5d commit 8cb3aa5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import Url from 'url';
import Opencc from 'opencc';
const opencc = new Opencc('tw2s.json');

import winston from 'winston';

let appLogger = new winston.Logger({
transports: [
new winston.transports.Console({
'timestamp': true,
'colorize': true
}),
],
});
let comicIndexer = new Indexer('./newdb');

let initLinks = [
Expand All @@ -21,7 +31,7 @@ let crawlers = initLinks.map(initLink => {


let index = (err, comicList) => {
if(err) console.log(err);
if(err) appLogger.log('error', err);
else {
let hostname = Url.parse(comicList[0].url).hostname;

Expand All @@ -40,7 +50,7 @@ let index = (err, comicList) => {
comicIndexer.add('dmeden', comicList);

else
console.log('can not find the proper indexer');
appLogger.log('error', 'can not find the proper indexer');
}
};

Expand Down
5 changes: 3 additions & 2 deletions src/lib/crawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ import Url from 'url';
// encode normalize
import charset from 'charset';
import iconv from 'iconv-lite';
import winston from 'winston';
import Opencc from 'opencc';
const opencc = new Opencc('tw2s.json');

import Parser from './parser';
import error from './error';
import winston from 'winston';

// do not use this class directly, extend it
class crawler {
constructor(baseUrl, delayTime){
this.logger = new winston.Logger({
transports: [
new winston.transports.Console({
'timestamp': true
'timestamp': true,
'colorize': true
}),
]
});
Expand Down
13 changes: 12 additions & 1 deletion src/lib/indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ import Sublevel from 'level-sublevel';
import Promise from 'bluebird';

import Opencc from 'opencc';
import winston from 'winston';

let opencc = new Opencc('tw2s.json');

class comicIndexer {
constructor(dbPath) {
this.logger = new winston.Logger({
transports: [
new winston.transports.Console({
'timestamp': true,
'colorize': true
}),
],
});
this.db = Sublevel(Levelup(dbPath));

// register sublevel
Expand All @@ -33,8 +43,9 @@ class comicIndexer {

// write to the correct sublevel db
try {
this.logger.log('info', '%s indexing', type);
this.comicDb[type].batch(ops, err => {
if(err) console.log(err);
if(err) this.logger.log('error', err);
});
} catch(TypeError) {
console.log('no such kind of db');
Expand Down

0 comments on commit 8cb3aa5

Please sign in to comment.