Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sidhantpanda/node-discord-logger
Use Discord for NodeJS application monitoring
https://github.com/sidhantpanda/node-discord-logger
Last synced: 4 days ago
JSON representation
Use Discord for NodeJS application monitoring
- Host: GitHub
- URL: https://github.com/sidhantpanda/node-discord-logger
- Owner: sidhantpanda
- Created: 2020-05-24T10:27:23.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T11:46:25.000Z (almost 2 years ago)
- Last Synced: 2024-10-28T11:03:12.714Z (16 days ago)
- Language: TypeScript
- Homepage: https://sidhantpanda.github.io/node-discord-logger/
- Size: 627 KB
- Stars: 12
- Watchers: 3
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node Discord Logger
Send logs to Discord from your NodeJS application.
[See detailed documentation](https://sidhantpanda.github.io/node-discord-logger/)### Installation
```
npm i -S node-discord-logger
```### Initialization
```javascript
import DiscordLogger from 'node-discord-logger';const logger = new DiscordLogger({
hook: 'https://your/discord/webhook',
icon: 'https://icon/for/service', // optional, will be included as an icon in the footer
serviceName: 'My NodeJS Service', // optional, will be included as text in the footer
defaultMeta: { // optional, will be added to all the messages
'Process ID': process.pid,
Host: os.hostname(), // import os from 'os';
},
errorHandler: err => { // optional, if you don't want this library to log to console
console.error('error from discord', err);
}
});
```## Usage
* Error Message
```javascript
logger.error({
message: 'This is an error message',
error: new Error('sample error') // This field can be included in other log functions as well
});
```
![error message example](https://raw.githubusercontent.com/sidhantpanda/public/master/img/projects/node-discord-logger/error-message.png)* Warning Message
```javascript
logger.warn({ message: 'This is warning message' });
```
![warning message example](https://raw.githubusercontent.com/sidhantpanda/public/master/img/projects/node-discord-logger/warning-message.png)* Debug Message
```javascript
logger.debug({
message: 'This is a debug message',
json: { debug: 'data' } // This field can be included in other log functions as well
});
```
![debug message example](https://raw.githubusercontent.com/sidhantpanda/public/master/img/projects/node-discord-logger/debug-message.png)* Info Message
```javascript
logger.info({
message: 'This is a info message',
description: 'Some additional description' // This field can be included in other log functions as well
});
```
![info message example](https://raw.githubusercontent.com/sidhantpanda/public/master/img/projects/node-discord-logger/info-message.png)* Verbose Message
```javascript
logger.verbose({ message: 'This is a verbose message' });
```
![verbose message example](https://raw.githubusercontent.com/sidhantpanda/public/master/img/projects/node-discord-logger/verbose-message.png)* Silly Message
```javascript
logger.silly({ message: 'This is a silly message' });
```
![silly message example](https://raw.githubusercontent.com/sidhantpanda/public/master/img/projects/node-discord-logger/silly-message.png)### LogMessage
| Field | Type | Description | Required |
|---|---|---|---|
| message | string | Main log message | **yes** |
| description | string | Log message description | no |
| error | Error | Error object to be logged with the message | no |
| meta | `{ [key: string]: string \| number \| Date }` | Meta details for log message | no |
| json | `any` (Valid JSON object) | Additional JSON to be logged in discord message | no |
---## Changelog
### v1.1.0
* Added `description` field in log message. [See usage](#usage_example_info_message).