How to use mwp-logger-plugin - 7 common examples

To help you get started, we’ve selected a few mwp-logger-plugin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github meetup / meetup-web-platform / packages / mwp-api-proxy-plugin / src / util / receive.js View on Github external
} catch (err) {
			// probably not JSON, could be an HTML response
			const titleContent = /<title>(.+?)&lt;\/title&gt;/.exec(body);
			errorMessage = titleContent ? titleContent[1] : 'REST API error';
		}
		logError({
			...logBase,
			body: body.length &gt; 512 ? `${body.substr(0, 512)}...` : body,
			err: new Error(errorMessage),
			context: response, // this will provide limited info - check apiRequest for more detail
		});
		return;
	}
	// not an error response - log in dev, not prod
	if (process.env.NODE_ENV !== 'production') {
		logger.info({
			...logBase,
			httpRequest: response,
		});
	}
};
</title>
github meetup / meetup-web-platform / packages / mwp-api-proxy-plugin / src / util / receive.js View on Github external
errorMessage = JSON.stringify(info.errors[0]) || body;
		} catch (err) {
			// probably not JSON, could be an HTML response
			const titleContent = /<title>(.+?)&lt;\/title&gt;/.exec(body);
			errorMessage = titleContent ? titleContent[1] : 'REST API error';
		}
		logError({
			...logBase,
			body: body.length &gt; 512 ? `${body.substr(0, 512)}...` : body,
			err: new Error(errorMessage),
			context: response, // this will provide limited info - check apiRequest for more detail
		});
		return;
	}
	// not an error response
	logger.info({
		...logBase,
		httpRequest: response,
	});
};
</title>
github meetup / meetup-web-platform / packages / mwp-api-proxy-plugin / src / util / receive.js View on Github external
export const makeLogResponse = request =&gt; ([response, body]) =&gt; {
	const {
		request: { headers, method, uri: { href: url } },
		statusCode,
	} = response;
	const logBase = {
		...request.raw, // request to /mu_api
		externalRequest: { headers, method, url }, // request to https://api.meetup.com/
	};

	if (
		statusCode &gt;= 500 || // REST API had an internal error
		(method.toLowerCase() === 'get' &amp;&amp; statusCode &gt;= 400) // something fishy with a GET
	) {
		const logError = (statusCode &lt; 500 ? logger.warn : logger.error).bind(
			logger
		);
		let errorMessage;
		try {
			// well-behaved API errors return a JSON object with an `errors` array
			const info = JSON.parse(body);
			errorMessage = JSON.stringify(info.errors[0]) || body;
		} catch (err) {
			// probably not JSON, could be an HTML response
			const titleContent = /<title>(.+?)&lt;\/title&gt;/.exec(body);
			errorMessage = titleContent ? titleContent[1] : 'REST API error';
		}
		logError({
			...logBase,
			body: body.length &gt; 512 ? `${body.substr(0, 512)}...` : body,
			err: new Error(errorMessage),</title>
github meetup / meetup-web-platform / packages / mwp-api-proxy-plugin / src / util / receive.js View on Github external
},
		statusCode,
	} = response;
	const logBase = {
		externalRequest: { headers, method, url }, // request to https://api.meetup.com/
	};

	if (
		statusCode &gt;= 500 || // REST API had an internal error
		(method.toLowerCase() === 'get' &amp;&amp; statusCode &gt;= 400) // something fishy with a GET
	) {
		if (isBot(request.headers['user-agent'])) {
			// don't log errors from bots - e.g. for deleted groups/events/whatever
			return;
		}
		const logError = (statusCode &lt; 500 ? logger.warn : logger.error).bind(logger);
		let errorMessage;
		try {
			// well-behaved API errors return a JSON object with an `errors` array
			const info = JSON.parse(body);
			errorMessage = JSON.stringify(info.errors[0]) || body;
		} catch (err) {
			// probably not JSON, could be an HTML response
			const titleContent = /<title>(.+?)&lt;\/title&gt;/.exec(body);
			errorMessage = titleContent ? titleContent[1] : 'REST API error';
		}
		logError({
			...logBase,
			body: body.length &gt; 512 ? `${body.substr(0, 512)}...` : body,
			err: new Error(errorMessage),
			context: response, // this will provide limited info - check apiRequest for more detail
		});</title>
github meetup / meetup-web-platform / packages / mwp-tracking-plugin / src / util / avro.js View on Github external
// @flow
const log = require('mwp-logger-plugin').logger;
const avro = require('avsc');
const uuidv1 = require('uuid/v1');
const AWS = require('aws-sdk');

const canUsePubSub =
	process.env.GAE_INSTANCE || process.env.GOOGLE_APPLICATION_CREDENTIALS;
const sts = new AWS.STS();

/*
 * There are currently 2 distinct analytics logging methods
 * 1. `stdout`: used in dev and compatible with https://github.com/meetup/blt-fluentd
 *    in k8s-based applications in GCP
 * 2. Google Pub/Sub, which is used in GAE and any environment with GOOGLE_APPLICATION_CREDENTIALS
 *    environment variable set to point toward Google JSON client credentials file
 *
 * @see https://meetup.atlassian.net/wiki/display/MUP/Analytics+Logging#AnalyticsLogging-Theinputmechanism
github meetup / meetup-web-platform / packages / mwp-test-utils / src / MockContainer.jsx View on Github external
function mapStateToProps(state) {
	logger.info(state);
	return {
		data: (state.api.foo || {}).value,
	};
}

mwp-logger-plugin

Hapi logging plugin for MWP apps

MIT
Latest version published 1 year ago

Package Health Score

39 / 100
Full package analysis

Similar packages