
Security News
Insecure Agents Podcast: Certified Patches, Supply Chain Security, and AI Agents
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.
English | 中文
Isomorphic logger wrapper.
ilw<Meta, Events>(options)
options <Object>
onLog <OnLog<Meta>>onEvent <OnEvent<Meta, Events>>persist <?boolean>report <?boolean>event <?boolean>meta <?Meta>Ilw<Meta, Events>>
options.event is falsyEventIlw<Meta, Events>>
options.event is trueIlw<Meta, Events>
ilw.persist <Ilw<Meta, Events>>ilw.report <Ilw<Meta, Events>>ilw.event <EventIlw<Meta, Events>>ilw.meta <(meta: Meta) => Ilw<Meta, Events>>ilw.debug <(...messages: unknown[]) => void>ilw.info <(...messages: unknown[]) => void>ilw.warn <(...messages: unknown[]) => void>ilw.error <(...messages: unknown[]) => void>EventIlw<Meta, Events>
ilw.persist <EventIlw<Meta, Events>>ilw.report <EventIlw<Meta, Events>>ilw.meta <(meta: Meta) => Ilw<Meta, Events>>ilw.debug <(type: keyof Events, value: Events[type]) => void>ilw.info <(type: keyof Events, value: Events[type]) => void>ilw.warn <(type: keyof Events, value: Events[type]) => void>ilw.error <(type: keyof Events, value: Events[type]) => void>OnLog
type OnLog<Meta = unknown> = (
level: Level,
messages: unknown[],
options: OnLogOptions<Meta>
) => void;
OnEvent
type OnEvent<
Meta = unknown,
Events extends Record<string, unknown> = Record<string, unknown>
> = <T extends keyof Events>(
level: Level,
event: {
type: T;
detail: Events[T];
},
options: OnLogOptions<Meta>
) => void;
OnLogOptions
type OnLogOptions<Meta = unknown> = {
event: boolean;
report: boolean;
persist: boolean;
meta: Meta | undefined;
};
import { ilw } from "ilw";
const logger = ilw({
// unified logging entry
// report - Whether to report
// persist - Whether to persist data
// meta - Meta message, anything
onLog(level, messages, { report, persist, meta }) {
if (report) {
// report by string
reporter.report(message.map(JSON.stringify).join(","));
} else if (persist) {
// Maybe your company's client logging SDK
nativeLogger(...messages);
} else {
// Or just print normally.
console[level](...messages);
}
},
// unified event logging entry
// type - Event type
// detail - Event detail
onEvent(level, { type, detail }, { report, persist, meta }) {
if (report) {
// report by eventName & params
eventReporter.report(type, detail);
} else if (persist) {
// Maybe your company's client logging SDK
nativeLogger("event", type, detail);
} else {
// Or just print normally.
console[level]("event", type, detail);
}
},
});
// report
logger.report.info("xxx", "yyy");
// persist
logger.persist.info("xxx", "yyy");
// event type
logger.event.info("eventName", {});
// Meta
logger.meta({ foo: "bar" }).info("xxx");
// any combinations
logger.persist.report.info("xx", "yyy");
// Use it like currify a function
const persistLogger = logger.persist;
persistLogger.info("xxx", "yyy");
const operationLogger = logger.meta({ scope: "operation" });
operationLogger.error("oops", new Error());
If you have made some relative complex apps, you will find logging & monitoring are important parts.
Since code quality can be influenced by different reasons, sometimes the only controlled part is logging, it's important to logging your app.
However there may be many conditions of logging itself:
These different conditions could use different library, or even in different devices. Every collaborator may have his thought. Finally the code will become messy.
If someone does some impilicit encapsulation of logging, it will be hard for new collaborators to understand what happens inside the logging code snippet.
So I try to merge those conditions into one adapter. At least I hope it can satisfy most demands.
FAQs
Isomorphic logger wrapper
The npm package ilw receives a total of 1 weekly downloads. As such, ilw popularity was classified as not popular.
We found that ilw demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.

Security News
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.