# strapi-plugin-bunyan

> Send Strapi error events to a log file using bunyan

Latest version **0.0.4** (published 2021-12-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install strapi-plugin-bunyan
pnpm add strapi-plugin-bunyan
yarn add strapi-plugin-bunyan
bun add strapi-plugin-bunyan
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2021-12-22 |
| First published | 2021-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.16.0 |
| Dependencies | 1 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tony Deplanque |
| Maintainers | todep |
| Keywords | strapi, plugin, strapi-plugin, strapi-logger, strapi-bunyan, strapi-permissions, logger, bunyan, log |

## Links

- npm: https://www.npmjs.com/package/strapi-plugin-bunyan
- Homepage: https://github.com/TonyDeplanque/strapi-plugin-bunyan
- Issues: https://github.com/TonyDeplanque/strapi-plugin-bunyan/issues
- npm.io page: https://npm.io/package/strapi-plugin-bunyan

## Dependencies (1)

- [bunyan](https://npm.io/package/bunyan.md) 1.8.15

## 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

- 0.0.4 (latest) — 2021-12-22
- 0.0.3 — 2021-12-21
- 0.0.2 — 2021-12-21

## README

# Strapi plugin Bunyan

Bunyan strapi plugin inspired by the official Strapi Bunyan plugin.

## 🧾 Features

- Initialize a Bunyan instance when your Strapi app starts
- Send errors encountered in your application's end API to a specific file in JSON format

## ⏳ Installation

To install this plugin, you need to add a NPM dependency to your Strapi application.

```sh
# Using Yarn
yarn add strapi-plugin-bunyan

# Or using NPM
npm install strapi-plugin-bunyan
```

## ⚙ Configuration

If you need to change error file location or the app name you must add your configuration in `./config/plugins.js`.

| property       | type  | description                                                                                                                                                                              |
| -------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `path`          | string(default:'./error.log')  | Log file location                                                                     |
| `appName` | string(default:'myapp') | Your application name provided in the logs                                                                         |

**Example**

`./config/plugins.js`

```js
module.exports = ({ env }) => ({
  // ...
    bunyan: {
        appName: 'goodProject',
        path: './error2.log',
    },
  // ...
});
```

If your log file path is inside your Strapi project, you need to add this lines in the config server file `./config/server.js`.Otherwise your server will restart each time the log file is changed.

`./config/server.js`
```js
module.exports = ({ env }) => ({
  // ...
    admin: {
        watchIgnoreFiles: [
            "./error.log"
        ]
    }
  // ...
});
```

## Global Bunyan service

You can access a Bunyan service throughout your app.

```js
const bunyanService = strapi.plugins.bunyan.services.bunyan;
```

This service exposes the following methods:

### `sendError(error)`

Use it to manually send errors to the log file. 

**Example**

```js
try {
  // Your code here
} catch (error) {
  strapi.plugins.bunyan.services.bunyan.sendError(error);
  throw error;
}
```

### `getInstance()`

Use it if you need direct access to the Bunyan instance, which should already already be initialized. It's useful if `sendError` doesn't suit your needs.

**Example**

```js
const bunyanInstance = strapi.plugins.bunyan.services.bunyan.getInstance();
```

## 🎉 Use Bunyan CLI

You can use the power of Bunyan CLI http://trentm.com/node-bunyan/bunyan.1.html

**Example**

```sh
./node_modules/.bin/bunyan error.log
```

## 💔 Disabling

### Disabling only the middleware

By default, this plugin uses a middleware that logs all your unhandled API errors to log file. You can disable this feature by turning off the `bunyan` middleware in your app's config.

**Example**

`./config/middleware.js`

```js
module.exports = {
  //...
  settings: {
    bunyan: {
      enabled: false,
    },
  },
};
```

Only the middleware will be disabled. You will still have access to the Bunyan service.

## 🤝 Contributing

Feel free to fork and make a Pull Request to this plugin project. All the input is warmly welcome!

## ⭐️ Show your support

Give a star if this project helped you.

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