Bascule sur le logger Winston
This commit is contained in:
21
src/util/app.js
Normal file
21
src/util/app.js
Normal file
@@ -0,0 +1,21 @@
|
||||
var ipc = require('ipc');
|
||||
var isMainProcess = process.type === 'browser';
|
||||
|
||||
var QUIT_CMD = 'app-util:quit';
|
||||
|
||||
exports.quit = function(exitCode) {
|
||||
if(isMainProcess) {
|
||||
process.exit(exitCode);
|
||||
} else {
|
||||
ipc.send(QUIT_CMD, exitCode);
|
||||
}
|
||||
};
|
||||
|
||||
// Main process, setup listeners
|
||||
if(isMainProcess) {
|
||||
|
||||
ipc.on(QUIT_CMD, function(evt, exitCode) {
|
||||
exports.quit(exitCode);
|
||||
});
|
||||
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
var debug = require('debug');
|
||||
var util = require('util');
|
||||
|
||||
module.exports = function createLogger(namespace) {
|
||||
var logger = debug('pitaya:'+namespace);
|
||||
return logger;
|
||||
};
|
@@ -1,6 +1,6 @@
|
||||
var path = require('path');
|
||||
var System = require('./system');
|
||||
var debug = require('./debug')('desktop-apps');
|
||||
var logger = require('./logger');
|
||||
var Cache = require('./cache');
|
||||
var promises = require('./promises');
|
||||
|
||||
@@ -80,18 +80,18 @@ exports.findIcon = function(iconName, themeName, size, themeIgnore) {
|
||||
var cachedIcon = iconCache.get([iconName, themeName, size]);
|
||||
|
||||
if(cachedIcon) {
|
||||
debug('Icon %s:%s:%s found in cache !', iconName, themeName, size);
|
||||
logger.debug('Icon %s:%s:%s found in cache !', iconName, themeName, size);
|
||||
return Promise.resolve(cachedIcon);
|
||||
}
|
||||
|
||||
themeIgnore = themeIgnore || [];
|
||||
if(themeIgnore.indexOf(themeIgnore) !== -1) {
|
||||
debug('Theme %s already processed, ignoring...', themeName);
|
||||
logger.debug('Theme %s already processed, ignoring...', themeName);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
themeIgnore.push(themeName);
|
||||
|
||||
debug('Finding icon %s:%s:%s...', iconName, themeName, size);
|
||||
logger.debug('Searching icon %s:%s:%s...', iconName, themeName, size);
|
||||
|
||||
if( ICON_REALPATH_REGEX.test(iconName) ) {
|
||||
return Promise.resolve(iconName);
|
||||
@@ -116,7 +116,7 @@ exports.findIcon = function(iconName, themeName, size, themeIgnore) {
|
||||
|
||||
if(foundIcon) return foundIcon;
|
||||
|
||||
debug('No icon found. Search in parents...');
|
||||
logger.debug('No icon found. Search in parents...');
|
||||
|
||||
return exports.findParentsThemeIcon(iconName, themeName, size, themeIgnore)
|
||||
.then(function(iconPath) {
|
||||
@@ -154,7 +154,7 @@ exports.findParentsThemeIcon = function(iconName, themeName, size, themeIgnore)
|
||||
|
||||
var parents = themeIndex['Icon Theme'].Inherits.split(',');
|
||||
|
||||
debug('Found parents %j', parents);
|
||||
logger.debug('Found parents', {parents: parents});
|
||||
|
||||
return promises.seq(parents, function(themeName) {
|
||||
return exports.findIcon(iconName, themeName, size, themeIgnore);
|
||||
@@ -177,16 +177,16 @@ exports.findClosestSizeIcon = function(iconName, themeName, size) {
|
||||
var extPattern = '{svg,png}';
|
||||
var filePattern = themeName+'/*/*/'+iconName+'.'+extPattern;
|
||||
|
||||
debug('File pattern %s', filePattern);
|
||||
logger.debug('File pattern %s', filePattern);
|
||||
|
||||
return System.findFiles(filePattern, {cwd: ICON_THEMES_ROOTDIR})
|
||||
.then(function(iconFiles) {
|
||||
|
||||
debug('Found files %j', iconFiles);
|
||||
logger.debug('Found files', {files: iconFiles});
|
||||
|
||||
var scalableIcon = iconFiles.reduce(function(scalableIcon, iconPath) {
|
||||
if(iconPath.indexOf('scalable') !== -1) {
|
||||
debug('Found scalable icon %s', iconPath);
|
||||
logger.debug('Found scalable icon %s', iconPath);
|
||||
scalableIcon = iconPath;
|
||||
}
|
||||
return scalableIcon;
|
||||
@@ -211,7 +211,7 @@ exports.findClosestSizeIcon = function(iconName, themeName, size) {
|
||||
|
||||
})
|
||||
.then(function(iconPath) {
|
||||
debug('Closest icon %j', iconPath);
|
||||
logger.debug('Closest icon', iconPath);
|
||||
return iconPath ? path.join(ICON_THEMES_ROOTDIR, iconPath) : null;
|
||||
})
|
||||
;
|
||||
@@ -229,7 +229,7 @@ exports.findClosestSizeIcon = function(iconName, themeName, size) {
|
||||
|
||||
exports.findPixmapsIcon = function(iconName) {
|
||||
var filePattern = iconName+'.{svg,png}';
|
||||
debug('Looking for pixmap icon %s', filePattern);
|
||||
logger.debug('Looking for pixmap icon %s', filePattern);
|
||||
return System.findFiles(filePattern, {cwd: PIXMAPS_ICONS_ROOTDIR})
|
||||
.then(function(iconPaths) {
|
||||
iconPaths = iconPaths.map(function(iconPath) {
|
||||
@@ -268,7 +268,7 @@ exports._selectBestIcon = function(iconPaths) {
|
||||
}
|
||||
return iconSelection;
|
||||
}, {scalable: null, bitmap: null});
|
||||
debug('Icon selection %j', iconSelection);
|
||||
logger.debug('Icon selection', iconSelection);
|
||||
return iconSelection.scalable || iconSelection.bitmap;
|
||||
};
|
||||
|
||||
|
@@ -1,7 +1,8 @@
|
||||
exports.System = require('./system');
|
||||
exports.DesktopApps = require('./desktop-apps');
|
||||
exports.Cache = require('./cache');
|
||||
exports.Debug = require('./debug');
|
||||
exports.Logger = require('./logger');
|
||||
exports.Tree = require('./tree');
|
||||
exports.Const = require('./const');
|
||||
exports.Promises = require('./promises');
|
||||
exports.App = require('./app');
|
||||
|
18
src/util/logger.js
Normal file
18
src/util/logger.js
Normal file
@@ -0,0 +1,18 @@
|
||||
var winston = require('winston');
|
||||
var logger = new winston.Logger({ exitOnError: true });
|
||||
|
||||
var logLevel = process.env.PITAYA_LOG_LEVEL || 'info';
|
||||
var logFile = process.env.PITAYA_LOG_FILE;
|
||||
|
||||
logger.level = logLevel;
|
||||
|
||||
logger.add(winston.transports.Console, { colorize: true });
|
||||
|
||||
if(logFile) {
|
||||
logger.add(winston.transports.File, {
|
||||
filename: logFile,
|
||||
json: false
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = logger;
|
Reference in New Issue
Block a user