Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@americanexpress/lumberjack
Advanced tools
Lumberjack is a minimal, configurable Console with utilities.
lumberjack
is a minimal and configurableConsole
with utilities.
Want to get paid for your contributions to lumberjack
?
Send your resume to oneamex.careers@aexp.com
Console
with utilities.formatter
depending on the log level.console
object using lumberjacknpm i @americanexpress/lumberjack
Read more about this in the Lumberjack API section.
import Lumberjack from '@americanexpress/lumberjack';
function createLogger(simple = true) {
return new Lumberjack({
formatter: simple
// your formatter function can be as simple as:
? (level, ...args) => `${level}: ${args}`
// or can be more complex, like stringifying as JSON:
: (level, ...messages) => JSON.stringify(
{
level,
messages,
time: new Date().toISOString(),
},
null,
2
),
});
}
const logger = createLogger();
logger.error(new Error('sample error'));
logger.warn("you're gonna have a bad time");
logger.info('%d', 42);
logger.log({ its: 'complicated' });
logger.dir(document.location); // lists properties of an object
logger.table(['apples', 'oranges', 'bananas']); // expects array
Read more about this in the monkeypatches API section.
import Lumberjack, { monkeypatches } from '@americanexpress/lumberjack';
const logger = new Lumberjack();
monkeypatches.replaceGlobalConsole(logger);
console.log('This is now invoking logger.log');
Creating a new console/Lumberjack is similar to creating a new nodejs Console, but slightly different:
const logger = new Lumberjack({
// options are added here
});
Options
are:
stdout
: stream to write to, defaults to process.stdout
stderr
: defaults to the stdout
optionformatter
: an optional function that gets the log level and raw input arguments to return a string that is written to the stream (either stdout
or stderr
depending on log level)
util.format
(nodejs Console's formatter)null
to skip writing to the streambeforeWrite
: callback function invoked before writing to the streamafterWrite
: callback function invoked after writing to the streamThe Lumberjack
instance has four methods: error
, warn
, info
, and log
.
A monkey patch is a way for a program to extend or modify supporting system software locally (affecting only the running instance of the program).
Use monkeypatches with care and be aware of pitfalls.
Replaces the error
, warn
, info
, and log
methods on the global console
object with those of the logger
argument provided.
import Lumberjack, { monkeypatches } from '@americanexpress/lumberjack';
const logger = new Lumberjack();
monkeypatches.replaceGlobalConsole(logger);
console.log('This is now invoking logger.log');
Spy on invocations of methods, ex: on native packages.
Arguments:
See also attachHttpRequestSpy and attachHttpsRequestSpy
import { monkeypatches } from '@americanexpress/lumberjack';
monkeypatches.attachSpy(http, 'request', (args, callOriginal) => {
console.log('starting http request', args);
const returnValue = callOriginal(); // spy, not an interceptor, so args handled automatically
console.log('http request started', returnValue);
});
Spy on the beginning and end of an http.request
.
Arguments:
http.request
http.request
Both spies receive the return value of http.request
and a normalized parsed URL requested (via url.parse
).
import { monkeypatches } from '@americanexpress/lumberjack';
monkeypatches.attachHttpRequestSpy(
(clientRequest, parsedUrl) => console.info(`started request to ${parsedUrl.href}`),
(clientRequest, parsedUrl) => console.info(`request to ${parsedUrl.href} finished`)
);
The same thing as attachHttpRequestSpy but for the https
native package.
Note that for nodejs versions before 6.0.0 and earlier https.request
called http.request
so adding spys for both
http
and https
will result in both spies being called.
We welcome Your interest in the American Express Open Source Community on Github. Any Contributor to any Open Source Project managed by the American Express Open Source Community must accept and sign an Agreement indicating agreement to the terms below. Except for the rights granted in this Agreement to American Express and to recipients of software distributed by American Express, You reserve all right, title, and interest, if any, in and to Your Contributions. Please fill out the Agreement.
Please feel free to open pull requests and see CONTRIBUTING.md to learn how to get started contributing.
Any contributions made under this project will be governed by the Apache License 2.0.
This project adheres to the American Express Community Guidelines. By participating, you are expected to honor these guidelines.
FAQs
Lumberjack is a minimal, configurable Console with utilities.
The npm package @americanexpress/lumberjack receives a total of 4 weekly downloads. As such, @americanexpress/lumberjack popularity was classified as not popular.
We found that @americanexpress/lumberjack demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.