@councilbox/logger

1.2.0-patch4 • Public • Published

CBX logger

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()],
    ...
});

Readme

Keywords

Package Sidebar

Install

npm i @councilbox/logger

Weekly Downloads

24

Version

1.2.0-patch4

License

ISC

Unpacked Size

10.3 kB

Total Files

7

Last publish

Collaborators

  • brunneis
  • cbx-npm
  • mirodriguez11
  • aaronfuentes