Skip to content

Commit

Permalink
Add Log plaug
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuzhuyule committed Jan 30, 2018
1 parent bd8997b commit 4a99d29
Show file tree
Hide file tree
Showing 11 changed files with 825 additions and 706 deletions.
13 changes: 7 additions & 6 deletions app/moe-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

const {dialog} = require('electron'),
MoeditorFile = require('./moe-file'),
log = log4js.getLogger('action.js'),
moment = require('moment'),
fs = require('fs'),
path = require('path');
Expand Down Expand Up @@ -98,7 +99,7 @@ class MoeditorAction {
}
}
} catch (e) {
console.log(e)
log.error(e)
} finally {
if (notOpened)
moeApp.open();
Expand Down Expand Up @@ -141,7 +142,7 @@ class MoeditorAction {
hexoWindow.focus();
break;
} catch (e) {
console.log(e);
log.error(e);
}
}
}
Expand Down Expand Up @@ -178,7 +179,7 @@ class MoeditorAction {
type: 'error',
content: __('Can\'t save file') + ', ' + e.toString()
});
console.log('Can\'t save file: ' + e.toString());
log.error('Can\'t save file: ' + e.toString());
return false;
}
}
Expand Down Expand Up @@ -222,7 +223,7 @@ class MoeditorAction {
type: 'error',
content: __('Can\'t save file') + ', ' + e.toString()
});
console.log('Can\'t save file: ' + e.toString());
log.error('Can\'t save file: ' + e.toString());
return false;
}
}
Expand Down Expand Up @@ -256,7 +257,7 @@ class MoeditorAction {
type: 'error',
content: __('Can\'t export as HTML') + ', ' + e.toString()
});
console.log('Can\'t export as HTML: ' + e.toString());
log.error('Can\'t export as HTML: ' + e.toString());
}
});
}
Expand All @@ -282,7 +283,7 @@ class MoeditorAction {
type: 'error',
content: __('Can\'t export as PDF') + ', ' + e.toString()
});
console.log('Can\'t export as PDF: ' + e.toString());
log.warn('Can\'t export as PDF: ' + e.toString());
}
try {
hexoWindow.hexoeditorWindow.window.webContents.send('pop-message', {
Expand Down
28 changes: 25 additions & 3 deletions app/moe-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

'use strict';

global.log4js = require('log4js');
const MoeditorWindow = require('./moe-window'),
MoeditorAction = require('./moe-action'),
MoeditorFile = require('./moe-file'),
Expand All @@ -38,6 +39,21 @@ class MoeditorApplication {
constructor() {
this.windows = new Array();
this.hexoWindow = null;
log4js.configure({
appenders: {
out: {type: 'stdout', level: 'all'},//设置是否在控制台打印日志
debugs: {type: 'file', filename: './logs/debug.log', level: 'debug',maxLogSize: 1024*1024*5},
infos: {type: 'file', filename: './logs/log.log', level: 'debug',maxLogSize: 1024*1024*5},
errors: { type: 'file', filename: './logs/error.log' ,maxLogSize: 1024*1024*2},
debug: { type: 'logLevelFilter', appender: 'debugs', level: 'debug' },
info: { type: 'logLevelFilter', appender: 'infos', level: 'info' },
error: { type: 'logLevelFilter', appender: 'errors', level: 'error' }
},
categories: {
default: {appenders: ['out', 'info', 'debug','error'], level: 'debug'}
}
})
global.log = log4js.getLogger('log');
}

open(fileName, defName) {
Expand All @@ -49,14 +65,18 @@ class MoeditorApplication {
}

getShellServer() {
if (!shellServer)
if (!shellServer){
log.info('create shellServer');
shellServer = new (require('./tool/hexo-shell'))();
}
return shellServer;
}

getUploadServer() {
if (!uploadServer)
if (!uploadServer) {
log.info('create uploadServer');
uploadServer = new (require('./tool/hexo-uploadServer'))();
}
return uploadServer;
}

Expand All @@ -71,7 +91,6 @@ class MoeditorApplication {

this.locale = new MoeditorLocale();
global.__ = str => this.locale.get(str);

this.flag = new Object();

const a = process.argv;
Expand Down Expand Up @@ -256,6 +275,9 @@ class MoeditorApplication {
setHexo(hexo) {
this.hexo = hexo;
}
getLog4js(){
return log4js;
}
}

MoeditorApplication.count = 0;
Expand Down
3 changes: 1 addition & 2 deletions app/moe-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const BrowserWindow = require('electron').BrowserWindow,
class MoeditorWindow {
constructor(path,defName) {
moeApp.hexoWindow = this;

log.info('create window');
if (MoeditorFile.isDirectory(path)) {
this.directory = path
this.fileName = '';
Expand Down Expand Up @@ -97,7 +97,6 @@ class MoeditorWindow {
}
}

console.log(this.window == moeApp.getShellServer().lastWindow)
if (this.window == moeApp.getShellServer().lastWindow)
process.nextTick(moeApp.getShellServer().kill,false);

Expand Down
Loading

0 comments on commit 4a99d29

Please sign in to comment.