Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@beforeyoubid/logger-adapter
Advanced tools
A platform logger module to send the log messages to LogDNA.
This is a platform logger module that is able to support multiple logging scenarios.
console
log wrapper so it can send all logs from the native console
object to LogDNA.This module is designed to work on a native node runtime and in a Lambda environment. For Lambda, please see the Flush All Messages section below.
console.log()
is not a recommended approach to be used for frontend application but it's fine to use in
the backend. Here are some limitations:
console
log object doesn't support the LOG_LEVEL
. For example, you may not want console.debug()
to
show debugging info on a production server.console
object as a pathway to adopting a logger
object.
If you are using console.log
on the existing code base and not ready to switch to Winston logger just yet, this module
can also helps you out as well.
yarn add @beforeyoubid/logger-adapter
We follow 12-factors and we can enable and send log to LogDNA by supplying LOGDNA_KEY as part of the environment variables.
LOGDNA_KEY=xxxxxxyyyyyyyzzzzzzz
Please note that on your local, you can set LOGDNA_KEY=
to disable sending logs to LogDNA. Supply LOG_LEVEL
as part
of the environment variable.
Additionally, you can keep LOGDNA_KEY
value the same way you set for other environments but can disable sending logs
by setting LOGDNA_ENABLED=false
in your env variables.
import { consoleLogger } from '@beforeyoubid/logger-adapter';
consoleLogger.init();
// Don't need to call consoleLogger.flushAll(), logdna object has default flush interval interval at 250ms
import { consoleLogger, flushAll } from '@beforeyoubid/logger-adapter';
consoleLogger.init();
// Ensure the we flush all messages before Lambda function gets terminated
const yourLambdaHandler = async (event, context) => {
try {
console.debug('Sample debug log - this message only show up when LOG_LEVEL is set to "debug"')
const result = await yourNormalProcess();
await flushAll(); // Trigger to flush all messages
return result;
} catch (e) {
// handle error
await flushAll(); // Trigger to flush all messages
// Throw or send result as usual
throw e;
// Or handle it nicely
// return unsuccessfulResponse;
}
}
import { consoleLogger, flushAll } from '@beforeyoubid/logger-adapter';
consoleLogger.init();
const yourLambdaHandler = (event, context, callback) => {
try {
console.debug('Sample debug log - this message only show up when LOG_LEVEL is set to "debug"')
const result = yourNormalProcess();
callback(null, yourNormalResponseObject);
flushAll(); // Trigger to flush all messages
} catch (e) {
// Ensure the we flush all messages before Lambda function gets terminated
flushAll(); // Trigger to flush all messages
// Call a callback with error
callback(yourErrorObject);
// Or return unsuccessful response
// https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format
// callback(null, unsuccessfulResponse);
}
}
import { consoleLogger, ensureFlushAll } from '@beforeyoubid/logger-adapter';
consoleLogger.init();
export default ensureFlushAll(graphqlHandler);
import { consoleLogger, ensureFlushAllCallback } from '@beforeyoubid/logger-adapter';
consoleLogger.init();
// Existing graphql hander - it uses callback signature
const graphqlHandler = server.createHandler({
cors: {
origin: '*',
allowedHeaders: ['x-api-token', 'Authorization'],
methods: ['GET', 'POST'],
},
});
export default ensureFlushAllCallback(graphqlHandler);
yarn add @beforeyoubid/logger-adapter
We follow 12-factors and we can enable and send log to LogDNA by supplying LOGDNA_KEY as part of the environment variables.
LOGDNA_KEY=xxxxxxyyyyyyyzzzzzzz
Please note that on your local, you can set LOGDNA_KEY=
to disable sending logs to LogDNA. Supply LOG_LEVEL
as part
of the environment variable.
import { logger } from '@beforeyoubid/logger-adapter';
logger.debug('This message only show up when LOG_LEVEL is set to "debug"')
logger.info('This message only show up when LOG_LEVEL is set to "info"')
import { logger, flushAll } from '@beforeyoubid/logger-adapter';
const yourLambdaHandler = async (event, context) => {
try {
logger.debug('Sample debug log - this message only show up when LOG_LEVEL is set to "debug"')
const result = await yourNormalProcess();
// Ensure the we flush all messages before Lambda function gets terminated
await flushAll();
return result;
} catch (e) {
// Ensure the we flush all messages before Lambda function gets terminated
await flushAll(); // Trigger to flush all messages
// Throw or send result as usual
throw e;
// Or handle it nicely
// return unsuccessfulResponse;
}
}
import { logger, flushAll } from '@beforeyoubid/logger-adapter';
const yourLambdaHandler = (event, context, callback) => {
try {
logger.debug('Sample debug log - this message only show up when LOG_LEVEL is set to "debug"')
const result = yourNormalProcess();
callback(null, yourNormalResponseObject);
// Ensure the we flush all messages before Lambda function gets terminated
flushAll(); // Trigger to flush all messages
} catch (e) {
// Ensure the we flush all messages before Lambda function gets terminated
flushAll(); // Trigger to flush all messages
// Call a callback with error
callback(yourErrorObject);
// Or return unsuccessful response
// https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format
// callback(null, unsuccessfulResponse);
}
}
LogDNA puts messages in the buffer and push out every 250ms. If Lambda is terminated before some of these intervals, it's likely that some of message logs are not sent to LogDNA.
We just need to ensure that after we've completed the business logic and before the Lambda function is terminated, we
flush all messages. We can just call a LogDNA flushAll()
function and this module export this logic for us to use.
Depending on how your Lambda handler is set up, but there are three variances we have observed.
createHandler()
functionPlease see usage examples from the above sections
FAQs
A platform logger module to send the log messages to Mezmo (formerly LogDNA).
We found that @beforeyoubid/logger-adapter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.