first commit
This commit is contained in:
commit
5260f4ff70
7 changed files with 487 additions and 0 deletions
86
README.md
Normal file
86
README.md
Normal file
|
@ -0,0 +1,86 @@
|
|||
# logger
|
||||
|
||||
A lightweight console and file logger with color-coded output and timestamped entries. Automatically includes the calling file and supports hourly log separation in saved files.
|
||||
|
||||
## Features
|
||||
|
||||
- Singleton logger instance
|
||||
- Colored console output
|
||||
- Log to file with date-based filenames
|
||||
- Hourly separators in saved logs
|
||||
- TypeScript-friendly with exported types
|
||||
- Supports `info`, `warn`, `error`, and `custom` log levels
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install @creations/logger
|
||||
```
|
||||
|
||||
Or with Bun:
|
||||
|
||||
```bash
|
||||
bun add @creations/logger
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { logger } from "@creations/logger";
|
||||
|
||||
logger.info("This is an info message");
|
||||
logger.warn("This is a warning", { breakLine: true });
|
||||
logger.error(new Error("Something went wrong"), { save: true });
|
||||
|
||||
logger.custom("[DEBUG]", "main.ts", "Detailed debug message", "34", {
|
||||
save: true,
|
||||
breakLine: true,
|
||||
});
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### logger.info(message, options?)
|
||||
|
||||
Log an informational message.
|
||||
|
||||
### logger.warn(message, options?)
|
||||
|
||||
Log a warning message.
|
||||
|
||||
### logger.error(message, options?)
|
||||
|
||||
Log an error message or exception.
|
||||
|
||||
### logger.custom(label, source, message, color, options?)
|
||||
|
||||
Log a custom message with a custom tag, source, and ANSI color code.
|
||||
|
||||
### logger.space()
|
||||
|
||||
Prints an empty line to the console.
|
||||
|
||||
## Options
|
||||
|
||||
All logging methods accept an optional object:
|
||||
|
||||
- `breakLine` (boolean): whether to add a newline after the message in the console
|
||||
- `save` (boolean): whether to write the message to the file log
|
||||
/
|
||||
## Types
|
||||
|
||||
```ts
|
||||
type ILogMessagePart = { value: string; color: string };
|
||||
|
||||
type ILogMessageParts = {
|
||||
level: ILogMessagePart;
|
||||
filename: ILogMessagePart;
|
||||
readableTimestamp: ILogMessagePart;
|
||||
message: ILogMessagePart;
|
||||
[key: string]: ILogMessagePart;
|
||||
};
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
Loading…
Add table
Add a link
Reference in a new issue