2.2.1 • Published 5 months ago
prime-console v2.2.1
⚡ 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
License
2.2.1
5 months ago
2.0.3
7 months ago
2.2.0
6 months ago
2.1.1
6 months ago
2.0.2
7 months ago
2.0.5
7 months ago
2.0.4
7 months ago
2.1.0
6 months ago
2.0.1
7 months ago
1.1.9
11 months ago
1.1.8
11 months ago
1.1.7
11 months ago
1.1.6
11 months ago
1.1.4
11 months ago
1.1.3
11 months ago
1.1.2
11 months ago
1.1.1
11 months ago
1.1.0
11 months ago
1.0.9
11 months ago
1.0.8
11 months ago
1.0.7
11 months ago
1.0.6
11 months ago
1.0.5
11 months ago
1.0.4
11 months ago
1.0.3
11 months ago
1.0.2
11 months ago
1.0.1
11 months ago
1.0.0
11 months ago