vkrus

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: MIT Imports: 6 Imported by: 0

README

vkrus

Build Status PkgGoDev codecov VK chat release license

Logrus hook for VK using VKSDK.

Usage

This library is packaged using Go modules. You can get it via:

# go mod init mymodulename
go get github.com/SevereCloud/vkrus/v2@latest

The hook must be configured with:

  • A peer ID (
    • For user: 'User ID', e.g. 12345
    • For chat: '2000000000' + 'chat_id', e.g. 2000000001 (chat_id for community)
  • Access Token with messages rights (found in your community settings)
package main

import (
	vkrus "github.com/SevereCloud/vkrus/v2"
	log "github.com/sirupsen/logrus"
)

func init() {
	peerID := 117253521   // USE strconv.Atoi(os.Getenv("PEER_ID"))
	groupToken := "token" // USE os.Getenv("TOKEN")
	hook := vkrus.NewHook(peerID, groupToken)
	hook.UseLevels = log.AllLevels

	log.AddHook(hook)
}

func main() {
	log.Trace("Something very low level.")
	log.Debug("Useful debugging information.")
	log.Info("Something noteworthy happened!")
	log.Warn("You should probably take a look at this.")
	log.Error("Something failed but I'm not quitting.")
}

DefaultLevels to be fired when logging on

var DefaultLevels = []logrus.Level{
	logrus.ErrorLevel,
	logrus.FatalLevel,
	logrus.PanicLevel,
}

Optional params:

  • AppName
  • UseLevels
  • Extra
  • Asynchronous
  • Disabled
  • DontParseLinks
  • DisableMentions
License

FOSSA Status

Documentation

Overview

Package vkrus VK Hook for Logrus

Index

Constants

This section is empty.

Variables

DefaultLevels to be fired when logging on

Functions

This section is empty.

Types

type VkHook

type VkHook struct {
	PeerID int // Destination ID
	VK     *api.VK

	AppName         string
	UseLevels       []logrus.Level
	Extra           map[string]interface{}
	Asynchronous    bool
	Disabled        bool
	DontParseLinks  bool // true - links will not attach snippet
	DisableMentions bool // true - mention of user will not generate notification for him
}

VkHook is a logrus Hook for dispatching messages to the specified channel on Slack.

PeerID - destination ID. For user: 'User ID', e.g. '12345'. For chat: '2000000000' + 'chat_id', e.g. '2000000001'

func NewHook

func NewHook(peerID int, token string) *VkHook

NewHook return VK Hook for Logrus

func (*VkHook) Fire

func (hook *VkHook) Fire(entry *logrus.Entry) error

Fire - Sent event to VK

func (*VkHook) Levels

func (hook *VkHook) Levels() []logrus.Level

Levels sets which levels to sent to VK

Jump to

Keyboard shortcuts

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