Commit 2c8b989f authored by Benjamin Bouvier's avatar Benjamin Bouvier
Browse files

Factor out the creation of loggers in a helper function (server);

parent f204401c
let log = require('printit')({
prefix: 'controllers/accesses',
date: true
});
import Access from '../models/access';
import Account from '../models/account';
import AccountManager from '../lib/accounts-manager';
import Errors from './errors';
import {sendErr, asyncErr} from '../helpers';
import {makeLogger, sendErr, asyncErr} from '../helpers';
let log = makeLogger('controllers/accesses');
let commonAccountManager = new AccountManager;
......
let log = require('printit')({
prefix: 'controllers/accounts',
date: true
});
import Account from '../models/account';
import Operation from '../models/operation';
import Access from '../models/access';
import Alert from '../models/alert';
import {sendErr, asyncErr} from '../helpers';
import {makeLogger, sendErr, asyncErr} from '../helpers';
let log = makeLogger('controllers/accounts');
// Prefills the @account field with a queried bank account.
export async function preloadAccount(req, res, next, accountID) {
......
......@@ -8,12 +8,9 @@ import OperationType from '../models/operationtype';
import Config from '../models/config';
import Cozy from '../models/cozyinstance';
import {sendErr, asyncErr} from '../helpers';
import {makeLogger, sendErr, asyncErr} from '../helpers';
let log = require('printit')({
prefix: 'controllers/all',
date: true
})
let log = makeLogger('controllers/all');
const ERR_MSG_LOADING_ALL = 'Error when loading all Kresus data';
......
let log = require('printit')({
prefix: 'controllers/banks',
date: true
});
import Bank from '../models/bank';
import Access from '../models/access';
import Account from '../models/account';
import * as AccountController from './accounts';
import {sendErr, asyncErr} from '../helpers';
import {makeLogger, sendErr, asyncErr} from '../helpers';
let log = makeLogger('controllers/banks');
// Preloads @bank in a request
export async function preloadBank(req, res, next, bankID) {
......
let log = require('printit')({
prefix: 'controllers/categories',
date: true
});
import Category from '../models/category';
import Operation from '../models/operation';
import {sendErr, asyncErr} from '../helpers';
import {makeLogger, sendErr, asyncErr} from '../helpers';
let log = makeLogger('controllers/categories');
export async function create(req, res) {
let cat = req.body;
......
let log = require('printit')({
prefix: 'controllers/settings',
date: true
});
import Config from '../models/config';
import * as weboob from '../lib/sources/weboob';
import {sendErr, asyncErr} from '../helpers';
import {makeLogger, sendErr, asyncErr} from '../helpers';
let log = makeLogger('controllers/settings');
export async function save(req, res) {
let pair = req.body;
......
let log = require('printit')({
prefix: 'http-error',
date: true
});
import printit from 'printit';
export function makeLogger(prefix) {
return printit({
prefix,
date: true
});
}
let log = makeLogger('helpers');
export function sendErr(res, context, statusCode = 500, userMessage = "Internal server error.", code) {
log.error(`Error: ${context} - ${userMessage}`);
......
let log = require('printit')({
prefix: 'init',
date: true
});
import {makeLogger} from './helpers';
import {promisify} from './helpers';
let log = makeLogger('init');
export default async (app, server, callback) => {
......
......@@ -6,14 +6,12 @@ import Account from '../models/account';
import OperationType from '../models/operationtype';
import Error from '../controllers/errors';
import {makeLogger} from '../helpers';
import alertManager from './alert-manager';
import Notifications from './notifications';
let log = require('printit')({
prefix: 'accounts-manager',
date: true
});
let log = makeLogger('accounts-manager');
// Add backends here.
const SOURCE_HANDLERS = {};
......
......@@ -6,11 +6,9 @@ import AccountManager from './accounts-manager';
import ReportManager from './report-manager';
import Error from '../controllers/errors';
import {makeLogger} from '../helpers';
let log = require('printit')({
prefix: 'accounts-poller',
date: true
});
let log = makeLogger('accounts-poller');
class AccountsPoller
{
......
......@@ -5,10 +5,9 @@ import Account from '../models/account';
import Alert from '../models/alert';
import Operation from '../models/operation';
let log = require('printit')({
prefix: 'alert-manager',
date: true
});
import {makeLogger} from '../helpers';
let log = makeLogger('alert-manager');
class AlertManager
{
......
import cozydb from 'cozydb';
import {promisify} from '../helpers';
import {makeLogger, promisify} from '../helpers';
let log = require('printit')({
prefix: 'emailer',
date: true
});
const DATA_SYSTEM_URL = "http://localhost:9101/";
let log = makeLogger('emailer');
class Emailer
{
......
import NotificationsHelper from 'cozy-notifications-helper';
import {makeLogger} from '../helpers';
import appData from '../../package.json';
let log = require('printit')({
prefix: 'notifications',
date: true
});
let log = makeLogger('notifications');
class Notifier
{
constructor() {
this.helper = new NotificationsHelper(appData.name);
if (process.kresus.standalone) {
// TODO fix this v
log.warn("Notification module in standalone mode is NYI.");
this.helper = {
createTemporary(params) {
log.warn("Trying to send a notification in standalone mode, which is NYI.");
}
};
} else {
// This helper only works within Cozy.
let NotificationsHelper = require('cozy-notifications-helper');
let appData = require('../../package.json');
this.helper = new NotificationsHelper(appData.name);
}
}
send(text) {
if (process.kresus.standalone) {
return log.warn("Trying to send a notification in standalone mode, which is NYI.");
}
let params = {
text,
resource: {
......
import moment from 'moment';
import {promisify} from '../helpers';
import {makeLogger} from '../helpers';
import Emailer from './emailer';
import Account from '../models/account';
import Alert from '../models/alert';
import Operation from '../models/operation';
let log = require('printit')({
prefix: 'report-manager',
date: true
});
let log = makeLogger('report-manager');
class ReportManager
{
......
// This modules mocks output generated by weboob.
import moment from 'moment' ;
let log = require('printit')({
prefix: 'sources/mock',
date: true
});
import {makeLogger} from '../../helpers';
let log = makeLogger('sources/mock');
const TIME_TO_GENERATE_OPERATIONS_MS = 500;
......
// This module retrieves real values from the weboob backend, by using the given
// bankuuid / login / password (maybe customFields) combination.
let log = require('printit')({
prefix: 'sources/weboob',
date: true
});
import {spawn} from 'child_process';
import {promisify} from '../../helpers';
import {makeLogger} from '../../helpers';
let log = makeLogger('sources/weboob');
export let SOURCE_NAME = 'weboob';
......
let log = require('printit')({
prefix: 'models/access',
date: true
});
import * as americano from 'cozydb';
import {promisify, promisifyModel} from '../helpers';
import {makeLogger, promisify, promisifyModel} from '../helpers';
let log = makeLogger('models/access');
let Access = americano.getModel('bankaccess', {
bank: String,
......
let log = require('printit')({
prefix: 'models/account',
date: true
});
import * as americano from 'cozydb';
import {promisify, promisifyModel} from '../helpers';
import {makeLogger, promisify, promisifyModel} from '../helpers';
import Operation from './operation';
import Operation from './operation'
let log = makeLogger('models/account');
let Account = americano.getModel('bankaccount', {
bank: String,
......
let log = require('printit')({
prefix: 'models/alert',
date: true
});
import * as americano from 'cozydb';
import {promisify, promisifyModel} from '../helpers';
import {makeLogger, promisify, promisifyModel} from '../helpers';
let log = makeLogger('models/alert');
let Alert = americano.getModel('bankalert', {
bankAccount: String,
......
let log = require('printit')({
prefix: 'models/bank',
date: true
});
import * as americano from 'cozydb';
import {promisify, promisifyModel} from '../helpers';
import {makeLogger, promisify, promisifyModel} from '../helpers';
let log = makeLogger('models/bank');
let Bank = americano.getModel('bank', {
name: String,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment