@councilbox/logger
v1.2.0-patch4
Published
Councilbox logger
Downloads
32
Readme
CONFIG
BASIC
const Logger = require('@councilbox/logger');
const logger = Logger({
name: 'API',
level: 'debug',
pretty: true
});
REDACT
const Logger = require('@councilbox/logger');
const logger = Logger({
name: 'API',
level: 'debug',
pretty: true,
redact: {
paths: [
'variables.pwd',
'variables.password',
'variables.vote',
'variables.dni',
'variables.tin',
'variables.base64',
'variables.certificate',
'result.nif'
],
remove: true,
}
});
GraphQL
const Logger = require('@councilbox/logger');
const logger = Logger({
name: 'API',
level: 'debug',
pretty: true,
graphqlConfig: {
excludedOperations: {
api: true
},
getUserId: (requestContext) => {
const user = requestContext.context.req.jwtSession;
return user.data ? user.data.id : null;
}
}
});
USAGE
BASIC
logger.info(`Version: ${logger.loggerVersion}`);
logger.debug('Hola');
logger.info('Hola');
logger.warn('Hola');
logger.error('Hola');
OUTPUT PRETTY
OUTPUT PLAIN
FORMATTED
const startTime = performance.now();
const debugLog = {
userId: '<USER_ID>',
result: {
response: 'sample response'
},
startTime,
debug: true,
endTime: performance.now(),
type: 'testing_log',
};
logger.formatter(debugLog);
const infoLog = {
userId: '<USER_ID>',
result: {
response: 'sample response'
},
startTime,
endTime: performance.now(),
type: 'testing_log',
};
logger.formatter(infoLog);
const warnlog = {
userId: '<USER_ID>',
result: {
response: 'sample response'
},
warn: true,
startTime,
endTime: performance.now(),
type: 'testing_log',
};
logger.formatter(warnlog);
const errorLog = {
userId: '<USER_ID>',
result: {
error: 'Default error'
},
startTime,
endTime: performance.now(),
type: 'testing_log',
};
logger.formatter(errorLog);
const errorsLog = {
userId: '<USER_ID>',
errors: ['Default error', 'Default error 2'],
startTime,
endTime: performance.now(),
type: 'testing_log',
};
logger.formatter(errorsLog);
OUTPUT PRETTY
OUTPUT PLAIN
GraphQL
new ApolloServer({
...,
plugins: [logger.graphql()],
...
});