prime-console
v2.2.1
Published
Easy to use logger for your node.js application
Downloads
18
Readme
⚡ Prime Console
Easy to use logger for your node.js application
Contents
Installation
Using npm:
npm i prime-console
Using yarn:
yarn add prime-console
Using pnpm:
pnpm i prime-console
Usage
Import already created instance. You can't configure it.
import { logger } from 'prime-console';
logger.info("Hello World!");
Create your own instance and configure it.
import { createLogger } from 'prime-console';
export const logger = createLogger(options: LoggerConfig);
See LoggerConfig
for more details.
Creating your own reporter
- There are two types of reporters:
- Within ReporterLevels you can create a reporter for each log level. These without a reporter will use the default reporter or the reporterOverride if it is set.
import { createLogger } from 'prime-console';
const logger = createLogger({
reporter: {
error: ({ message, type, timestamp, icon, color }, options) => {
console.log(`[${timestamp}] ${icon} ${message}`);
} // This will override the default reporter for error level
},
reporterOverride: ({ message, type, timestamp, icon, color }, options) => {
console.log(`[${timestamp}] ${icon} ${message}`);
} // Level that aren't custom configured will fallback to this reporter
})
Types
LoggerConfig
export type LoggerConfig = Partial<{
level: number;
files: Partial<{
path: string; // Path to the folder where the logs will be saved
extension: "text" | "json";
fileName: string; // Name of the file
}>;
format: Partial<{
colors: boolean;
timestamp: boolean;
}>;
reporter: ReporterLevels;
reporterOverride: ReporterOverride;
}>;
ReporterLevels
export type ReporterLevels = Partial<{
[key in LogType]: (
{ message, type, timestamp, icon, color }: ReporterObject,
options: LoggerConfig,
) => void;
}>;
ReporterOverride
// If this reporterOverride is set in a logger instance, it will override level that aren't custom configured
export type ReporterOverride = (
{ message, type, timestamp, icon, color }: ReporterObject,
options: LoggerConfig,
) => void;
Contributing
Pull requests and stars are always welcome. See contributing.md
for ways to get started.
This repository has a code of conduct
. By interacting with this repository, organization, or community you agree to abide by its terms.
Note
- Default styles were strongly inspired by
consola