# @gecut/logger

> Fancy colorful console debugger with custom scope written in tiny TypeScript, ES module.

Latest version **7.0.3** (published 2024-10-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @gecut/logger
pnpm add @gecut/logger
yarn add @gecut/logger
bun add @gecut/logger
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 7.0.3 |
| Published | 2024-10-25 |
| First published | 2023-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 26.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | S. MohammadMahdi Zamanian |
| Maintainers | mm25zamanian |
| Keywords | log, logger, console, debug, typescript, esm, gecut |

## Links

- npm: https://www.npmjs.com/package/@gecut/logger
- Repository: https://github.com/gecut/hybrid-core
- Issues: https://github.com/gecut/hybrid-core/issues
- npm.io page: https://npm.io/package/@gecut/logger

## Dependencies (1)

- [@gecut/utilities](https://npm.io/package/@gecut/utilities.md) ^7.0.3

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 7.0.3 (latest) — 2024-10-25
- 1.0.0 (next) — 2023-12-20
- 7.0.2 — 2024-10-25
- 2.0.0 — 2024-10-08
- 1.4.7 — 2024-09-09
- 1.4.6 — 2024-07-06
- 1.4.5 — 2024-07-04
- 1.4.4 — 2024-06-12
- 1.4.3 — 2024-06-11
- 1.4.2 — 2024-05-25
- 1.4.1 — 2024-05-09
- 1.4.0 — 2024-05-04
- 1.3.1-alpha.0 — 2024-03-06
- 1.3.0 — 2024-03-04
- 1.2.3 — 2024-01-07
- … 6 more at https://npm.io/package/@gecut/logger/versions

## README

# @gecut/logger

Gecut Logger is a flexible and colorful logging tool built to enhance your debugging experience for both Node.js and browser-based JavaScript applications. With environment-aware functionalities and stylish output, Gecut Logger helps you to keep track of your application's behavior in an organized and visually appealing way.

## Features 🚀

- **Environment Compatibility**: Works seamlessly in both Node.js and browser environments.
- **Debug Modes**: Easily toggle debugging on and off with DEV_MODE, taking advantage of the localStorage in browsers and environment variables in Node.js.
- **Color Coding**: A colorful logging experience with auto-rotating colors to distinguish logs in both the browser console and terminal.
- **Structured Logging**: Logs are presented with indices, domains, and scope stylings to make tracing easier.
- **Development Friendly**: Rich debug functions available during development for an in-depth examination of your code.
- **Sub-Loggers**: Create sub-loggers with inherited features from a parent logger to maintain the context during complex application workflows.

## Installation 📦

Install the package using npm:

```bash
npm install @gecut/logger
```

## Usage 🛠️

Getting started with Gecut Logger is straightforward:

```ts
import {GecutLogger} from '@gecut/logger';

const logger = new GecutLogger('MyApp');

// Log an error with a method and description
logger.error('init', 'INIT_FAIL', 'Initialization failed due to an unknown error');

// Warn with additional arguments
logger.warning('loadData', 'INVALID_RESPONSE', 'Data response is invalid', {userId: 1});

// Begin a timed operation (development mode only)
logger.time?.('fetchData');
// code to fetch data here...
logger.timeEnd?.('fetchData');
```

### Example in Browser 🌐

```ts
// Assuming DEV_MODE is enabled in localStorage
const logger = new GecutLogger('UIComponent');

// Trace a method call and its arguments
logger.methodArgs?.('render', {items: 5});

// Log a property change
logger.property?.('isVisible', true);

// Other custom logs
logger.other?.('The component has been successfully rendered');
```

### Example in Node.js 🖥️

```ts
const logger = new GecutLogger('Server');

// Log an error with detailed information
logger.error('start', 'STARTUP_ERROR', 'Server failed to start on port 3000');

// Log a method entry
logger.method?.('handleRequest');
```

### Sub-Logger Creation 🧱

```ts
const mainLogger = new GecutLogger('App');
const dbLogger = mainLogger.sub('Database');

dbLogger.error('query', 'QUERY_FAIL', 'Query to the products table failed');
```

## API Documentation 📖

### GecutLogger

- **constructor(domain: string, devMode?: boolean)**: Initializes a new logger instance with a domain namespace and an optional development mode flag.

### Methods

- **property(property: string, value: unknown)**: Logs a property change (development mode only).
- **method(method: string)**: Logs a method invocation (development mode only).
- **methodArgs(method: string, args: unknown)**: Logs a method call with its arguments (development mode only).
- **methodFull(method: string, args: unknown, result: unknown)**: Logs a method with arguments and the result (development mode only).
- **other(...args: unknown[])**: Logs any custom information (development mode only).
- **warning(method: string, code: string, desc: string, ...args: unknown[])**: Logs a warning message, with a method reference, warning code, description, and additional arguments.
- **error(method: string, code: string, ...args: unknown[])**: Logs an error message, with a method reference, error code, and additional arguments.

### Static Methods

- **sub(domain: string, devMode?: boolean)**: Creates a sub-logger with a specified domain scope and optional development mode flag.

## Contributing 🤝

Your contributions are always welcome! If you have suggestions or find bugs, feel free to submit an issue or pull request on our [GitHub repository](https://github.com/gecut/gecut).

## License 📄

This project is licensed under the MIT License - see the LICENSE file for details.

Bring some color and structure to your debugging efforts with Gecut Logger! 🎨🔍

---
_Source: https://npm.io/package/@gecut/logger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
