Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
json-log-line
Advanced tools
This utility is designed to take JSON and plain objects and convert them into log line strings. It's compatible with any nd JSON logger.
JSON and Plain Object Support: This utility can handle both JSON and plain objects, providing flexibility in the types of data you can convert into log line strings.
Compatible with any nd JSON Logger: This utility is designed to work with any nd JSON logger, making it a versatile tool for your logging needs.
To install this utility, use the following command:
npm install json-log-line
To use this utility, simply pass your JSON or plain object to the logLineFactory
function:
const options = {
/**
* The key to use for the error object. Defaults to `err`.
*/
errorKey: "err",
/**
* include and exclude both take keys with dot notation
*/
exclude: [],
/**
* include always overrides exclude
*/
include: [],
/**
* Format functions for any given key, keys of the object are automatically included and cannot be excluded
* You can use dot notation as the object keys. The keys will print in order.
*/
format: {
some: (obj: any) => {
return obj["some-key"].toString();
},
part: (obj: any) => {
return obj["some-key"].toString();
},
of: (obj: any) => {
return obj["some-key"].toString();
},
log: (obj: any) => {
return obj["some-key"].toString();
},
},
};
export const lineFormatter = logLineFactory(yourObject);
This will return a formatter that can process strings or object output from any nd JSON logger.
example:
import { logLineFactory } from "json-log-line";
const options = {
include: ["nested.field"],
exclude: ["nested"],
format: {
part1: (value) => `[${value}]`,
part2: (value) => `[${value}]`,
"nested.field": (value) => `:${value}:\n`,
},
};
const lineFormatter = logLineFactory(options);
const log = JSON.stringify({
nested: {
other: "something",
field: "FIELD",
},
part1: "hello",
part2: "world",
some: "extra",
data: "here",
});
console.log(lineFormatter(log));
// =>
// [hello] [world] :FIELD:
// {"some":"extra","data":"here"}
Often times you will want to stream nd json logs into a function that formats each log.
Record<keyof parsed log object, () => string>
Format is an object the represents how you want to parse the log object. It will parse in natural order of the object.
A special key that contains the rest of the log object fields which were both included and not formatted by a format function.
string[]
An array of object keys to include. Overrides excludes. All keys are included by default.
string[]
An array of object keys to exclude. The keys can be nested. Can be overridden with a more deeply nested include.
FAQs
A utility for building awesome log lines from JSON
We found that json-log-line 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.