first commit

This commit is contained in:
creations 2025-04-22 20:01:08 -04:00
commit 5260f4ff70
Signed by: creations
GPG key ID: 8F553AA4320FC711
7 changed files with 487 additions and 0 deletions

86
README.md Normal file
View 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)