1.0.3 • Published 2 years ago

log2discord v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

log2discord

Log2discord is a logging module that logs events and errors to Discord.

Install

# with npm
npm install log2discord

Configuration

Log2discord requires the use of Discord webhooks. Instructions on how to obtain a webhook url can be found here.

Example configuration

import log2discord from 'log2discord';
const logger = new log2discord.Logger({
    webhook: "https://discord.com/api/webhooks/<id>/<token>", // Discord webhook token
    icon: "https://linktoyourappicon.com/icon.png", // Will be used as profile photo
    name: "YourApp",
    pid: true,
    host: true,
    dateTime: {
        timeZone: "America/New_York",
        locale: "en-US"
    }
});

Available configuration options

OptionTypeDescriptionNotes
webhookstringA valid Discord webhook URLIt is recommended to store your webhook using .env
iconstringA valid image URLOptional
namestringYour application nameOptional
pidbooleanDisplay process idOptional
hostbooleanDisplay hostnameOptional
dateTimeobject or falseDisplay date and timeOptional
timeZonestringYour chosen timezone (Default is UTC)Optional
localestringYour chosen localeOptional

Usage

Error

logger.error({
    title: "Error message title",
    message: "This is an error message 🛑",
    error: Error("Example error") // Can also be an error callback
})

Error log example

Warning

logger.warn({
    title: "Warning message title",
    message: "This is a warning message 🚧",
})

Warning log example

Debug

logger.debug({
    title: "Debug message title",
    message: "This is a debug message 🐛",
    json: {
        valid: "JSON object"
    }
})

Debug log example

Info

logger.info({
    title: "Info message title",
    message: "This is an info message 🔤",
})

Info log example

Custom

logger.custom({
    type: "CUSTOM",
    color: 123,
    title: "Custom message title",
    message: "This is a custom message 🦄",
    json: {
        valid: "JSON object"
    }
})

Custom log example

Available logging options

OptionTypeDescriptionNotes
messagestringA message to be logged
titlestringTitle for your log messageOptional
typestringA custom log level(Optional). Will only be parsed if logger.custom(...) is used
colornumberA color in decimal format(Optional). Will only be parsed if logger.custom(...) is used
jsonjsonA valid json objectOptional
errorErrorLog the error stackOptional
1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago