logging

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

README

logging

This module provides thread-safe logging and Discord notifications as a part of our Mirror project.

Screenshot

There are plenty of low-priority improvements that can be made to this module.

Usage

go get "github.com/COSI-Lab/logging"

Example:

package main

import (
    "github.com/COSI-Lab/logging"
)

func main() {
    // Optional: If you only want messages to be displayed in the terminal there is no need to run `Setup`
    // logging.Setup("https://discord.com/api/webhooks/987654321123456789/S3cR3TwebH00KuRl", "01234567890123456789")

    ch := make(chan struct{})

    go func() {
        // The last argument to all the logging functions is a variadic ...interface{} which is eventually evulated with fmt.Println(...v)
        logging.InfoWithAttachment(bytes("Attachment"), "Hello", "World!")
        ch <- struct{}{}
    }()

    go func() {
        logging.ErrorToDiscord("This subsystem failed!")
        ch <- struct{}{}
    }()

    <-ch
    <-ch
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(v ...interface{})

Error logs a message to the terminal with [ERROR] prefix

func ErrorToDiscord

func ErrorToDiscord(v ...interface{})

ErrorToDiscord logs a message to the terminal with [ERROR] prefix The message is also forwarded to the Discord server without pinging users

func ErrorWithAttachment

func ErrorWithAttachment(attachment []byte, v ...interface{})

ErrorWithAttachment logs a message to the terminal with [ERROR] prefix If we can send a webhook, the message and attachment are forwarded to the Discord server without pinging users If we cannot send a webhook the attachment is sent to the terminal

func Info

func Info(v ...interface{})

Info logs a message to the terminal with [INFO] prefix

func InfoToDiscord

func InfoToDiscord(v ...interface{})

InfoToDiscord logs a message to the terminal with [INFO] prefix The message is also forwarded to the Discord server without pinging users

func InfoWithAttachment

func InfoWithAttachment(attachment []byte, v ...interface{})

InfoWithAttachment logs a message to the terminal with [INFO] prefix If we can send a webhook, the message and attachment are forwarded to the Discord server without pinging users If we cannot send a webhook the attachment is sent to the terminal

func Panic

func Panic(v ...interface{})

Panic logs a message to the terminal with [PANIC] prefix

func PanicToDiscord

func PanicToDiscord(v ...interface{})

PanicToDiscord logs a message to the terminal with [PANIC] prefix The message is also forwarded to the Discord server and pings the users

func PanicWithAttachment

func PanicWithAttachment(attachment []byte, v ...interface{})

PanicWithAttachment logs a message to the terminal with [PANIC] prefix If we can send a webhook, the message and attachment are forwarded to the Discord server and pings the users If we cannot send a webhook the attachment is sent to the terminal

func Setup

func Setup(hookURL, pingID string)

Setup primes the threadSafeLogger to send messages to a Discord server hookURL is the weebhook URL created by the Discord server in the Integrations settings pingID is the Discord user or role ID to ping when sending important messages Setup can be safely called at any time to change the Discord server hookURL and pingID

func Success

func Success(v ...interface{})

Success logs a message to the terminal with [SUCCESS] prefix

func SuccessToDiscord

func SuccessToDiscord(v ...interface{})

SuccessToDiscord logs a message to the terminal with [SUCCESS] prefix The message is also forwarded to the Discord server without pinging users

func SuccessWithAttachment

func SuccessWithAttachment(attachment []byte, v ...interface{})

SuccessWithAttachment logs a message to the terminal with [SUCCESS] prefix If we can send a webhook, the message and attachment are forwarded to the Discord server without pinging users If we cannot send a webhook the attachment is sent to the terminal

func Warn

func Warn(v ...interface{})

Warn logs a message to the terminal with [WARN] prefix

func WarnToDiscord

func WarnToDiscord(v ...interface{})

WarnToDiscord logs a message to the terminal with [WARN] prefix The message is also forwarded to the Discord server without pinging users

func WarnWithAttachment

func WarnWithAttachment(attachment []byte, v ...interface{})

WarnWithAttachment logs a message to the terminal with [WARN] prefix If we can send a webhook, the message and attachment are forwarded to the Discord server without pinging users If we cannot send a webhook the attachment is sent to the terminal

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL