npm package: @nithin-sivakumar/logger
Description: A simple logger for Express.js that logs to console and file.
Author: Nithin Sivakumar
Latest version: 1.0.11

# SimpleLogger

`SimpleLogger` is a logging utility that integrates `morgan` for HTTP request logging and `winston` for logging to files and the console. It allows for easy customization of log formats and levels, making it a flexible solution for Express applications.

## Features

- **HTTP Request Logging**: Logs HTTP requests using `morgan` with customizable formats.
- **File Logging**: Logs server information in a JSON format to a file, ensuring persistence.
- **Console Logging**: Logs information to the console with colors for better readability.
- **Customizable**: You can change the log format, log level, and decide if you want customized colors for HTTP status codes.
- **Easy Integration**: Easily integrates into Express applications as middleware.

## Installation

```bash
npm install @nithin-sivakumar/logger
```

## Usage

### Basic Usage

```javascript
import express from "express";
import createLogger from "@nithin-sivakumar/logger";

const app = express();

// Initialize logger with default options
app.use(createLogger());

// Your routes here
app.get("/", (req, res) => {
  res.send("Hello, world!");
});

app.listen(3000, () => {
  console.log("Server is running on port 3000");
});
```

### Customizing the Logger

You can customize the logger's format, log level, and whether it should use custom colors for HTTP status codes.

```javascript
import express from "express";
import createLogger from "@nithin-sivakumar/logger";

const app = express();

// Customize logger
const logger = createLogger({
  format: "combined", // morgan log format
  level: "debug", // winston log level
  customize: true, // Use custom colors for status codes
});

app.use(logger);

// Your routes here
app.get("/", (req, res) => {
  res.send("Hello, world!");
});

app.listen(3000, () => {
  console.log("Server is running on port 3000");
});
```

## Logger Configuration Options

- **`format`**: The log format for `morgan`. Available values are:

  - `"dev"`: Concise colored output (for development).
  - `"combined"`: Standard Apache combined log format.
  - `"tiny"`: Shorter, minimal log format.
  - Custom format string (for `morgan`).

- **`level`**: The log level for `winston`. Available values are:

  - `"info"`: Logs general information.
  - `"warn"`: Logs warnings.
  - `"error"`: Logs errors.
  - `"debug"`: Logs debug information.
  - `"verbose"`: Logs more detailed information.

- **`customize`**: Whether to customize the log output with colors based on HTTP status. Defaults to `true`.

## API

### `createLogger(options)`

Creates a logger middleware for use in Express applications.

#### Parameters

- **`options`** (optional): Configuration options for the logger.

  - **`format`** (optional): The log format for `morgan`. Defaults to `"dev"`.
  - **`level`** (optional): The log level for `winston`. Defaults to `"info"`.
  - **`customize`** (optional): Whether to customize the log output with colors. Defaults to `true`.