Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# discordrus | a [Discord](https://discordapp.com/) hook for [Logrus](https://github.com/Sirupsen/logrus) <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/> [![Travis CI](https://api.travis-ci.org/kz/discordrus.svg?branch=master)](https://travis-ci.org/kz/discordrus) [![GoDoc](https://godoc.org/github.com/puddingfactory/logentrus?status.svg)](https://godoc.org/github.com/kz/discordrus)

**Current version:** v1.0.1
**Current version:** v1.1.0

![Screenshot of discordrus in action](http://i.imgur.com/zvDNDjV.png)

Expand All @@ -21,8 +21,8 @@ Below is an example of how this package may be used. The options below are used
package main

import (
"os"
"github.com/Sirupsen/logrus"
"github.com/sirupsen/logrus"
"os"
"github.com/kz/discordrus"
)

Expand All @@ -37,11 +37,12 @@ func init() {
// Set minimum level to DebugLevel to receive all log entries
logrus.DebugLevel,
&discordrus.Opts{
Username: "Test Username",
Author: "", // Setting this to a non-empty string adds the author text to the message header
DisableTimestamp: false, // Setting this to true will disable timestamps from appearing in the footer
TimestampFormat: "Jan 2 15:04:05.00000", // The timestamp takes this format; if it is unset, it will take logrus' default format
EnableCustomColors: true, // If set to true, the below CustomLevelColors will apply
Username: "Test Username",
Author: "", // Setting this to a non-empty string adds the author text to the message header
DisableTimestamp: false, // Setting this to true will disable timestamps from appearing in the footer
TimestampFormat: "Jan 2 15:04:05.00000 MST", // The timestamp takes this format; if it is unset, it will take logrus' default format
TimestampLocale: nil, // The timestamp uses this locale; if it is unset, it will use time.Local
EnableCustomColors: true, // If set to true, the below CustomLevelColors will apply
CustomLevelColors: &discordrus.LevelColors{
Debug: 10170623,
Info: 3581519,
Expand All @@ -68,7 +69,8 @@ Username | Replaces the default username of the webhook bot for the sent message
Author | Adds an author field to the header if set | Author not set | Any non-empty string (1-256 chars inclusive)
DisableInlineFields | Inline means whether Discord will display the field in a column (with maximum three columns to a row). Setting this to `true` will cause Discord to display the field in its own row. | false | bool
DisableTimestamp | Specifies whether the timestamp in the footer should be disabled | false | bool
TimestampFormat | Change the timestamp format | logrus's default time format | `"Jan 2 15:04:05"`, or any format accepted by Golang
TimestampFormat | Change the timestamp format | logrus's default time format | `"Jan 2 15:04:05.00000 MST"`, or any format accepted by Golang
TimestampLocale | Change the timestamp locale | `nil` | nil == time.Local, time.UTC, time.LoadLocation("America/New_York"), etc
EnableCustomColors | Specifies whether the `CustomLevelColors` opt value should be used instead of `discordrus.DefaultLevelColors`. If `true`, `CustomLevelColors` must be specified (or all colors will be set to the nil value of `0`, therefore displayed as white) | false | bool
CustomLevelColors | Replaces `discordrus.DefaultLevelColors`. All fields must be entered or they will default to the nil value of `0`. | Pointer to struct instance of `discordrus.LevelColors`

Expand Down
6 changes: 6 additions & 0 deletions discordrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/sirupsen/logrus"
"time"
)

const (
Expand Down Expand Up @@ -37,6 +38,8 @@ type Opts struct {
DisableTimestamp bool
// TimestampFormat specifies a custom format for the footer
TimestampFormat string
// TimestampLocale specifies a custom locale for the timestamp
TimestampLocale *time.Location
}

// Hook is a hook to send logs to Discord
Expand Down Expand Up @@ -127,6 +130,9 @@ func (hook *Hook) parseToJson(entry *logrus.Entry) (*[]byte, error) {

// Add footer to embed
if !hook.Opts.DisableTimestamp {
if hook.Opts.TimestampLocale != nil {
entry.Time = entry.Time.In(hook.Opts.TimestampLocale)
}
timestamp := ""
if hook.Opts.TimestampFormat != "" {
timestamp = entry.Time.Format(hook.Opts.TimestampFormat)
Expand Down
9 changes: 5 additions & 4 deletions discordrus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ func init() {
logrus.DebugLevel,
&Opts{
Username: "Test Username",
Author: "", // Setting this to a non-empty string adds the author text to the message header
DisableTimestamp: false, // Setting this to true will disable timestamps from appearing in the footer
TimestampFormat: "Jan 2 15:04:05.00000", // The timestamp takes this format; if it is unset, it will take logrus' default format
EnableCustomColors: true, // If set to true, the below CustomLevelColors will apply
Author: "", // Setting this to a non-empty string adds the author text to the message header
DisableTimestamp: false, // Setting this to true will disable timestamps from appearing in the footer
TimestampFormat: "Jan 2 15:04:05.00000 MST", // The timestamp takes this format; if it is unset, it will take logrus' default format
TimestampLocale: nil, // The timestamp uses this locale; if it is unset, it will use time.Local
EnableCustomColors: true, // If set to true, the below CustomLevelColors will apply
CustomLevelColors: &LevelColors{
Debug: 10170623,
Info: 3581519,
Expand Down