skip ANSI color commands
ref: https://github.com/gin-gonic/gin/pull/754 Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
c5bba12d76
commit
c9873b1644
|
@ -1,5 +1,5 @@
|
|||
hash: cccd36b5dd331f04f363476ebc21becfa3650945e3fd0b41821871702bc04743
|
||||
updated: 2016-12-14T00:05:23.060124146+08:00
|
||||
hash: 54ead355ba6aeef8f2ea2ea1b5a473e2ce21371831e06355001dbc9b4dc18e22
|
||||
updated: 2016-12-14T22:43:06.161105893+08:00
|
||||
imports:
|
||||
- name: github.com/asdine/storm
|
||||
version: 00b2f2df7ab7af9db746b826649395628cb5374e
|
||||
|
@ -12,7 +12,7 @@ imports:
|
|||
- name: github.com/fvbock/endless
|
||||
version: 2cdc20a776897c0f406853c048c33e2c1a9f0ebf
|
||||
- name: github.com/gin-gonic/gin
|
||||
version: f931d1ea80ae95a6fc739213cdd9399bd2967fb6
|
||||
version: e2212d40c62a98b388a5eb48ecbdcf88534688ba
|
||||
subpackages:
|
||||
- binding
|
||||
- render
|
||||
|
@ -28,6 +28,8 @@ imports:
|
|||
version: 0496a6c14df020789376f4d4a261273d5ddb36ec
|
||||
- name: github.com/manucorporat/sse
|
||||
version: ee05b128a739a0fb76c7ebd3ae4810c1de808d6d
|
||||
- name: github.com/mattn/go-isatty
|
||||
version: 3a115632dcd687f9c8cd01679c83a06a0e21c1f3
|
||||
- name: github.com/mattn/go-xmpp
|
||||
version: e44d1877bb457f5c3991903e9934a31e55c3a2ad
|
||||
- name: github.com/pborman/uuid
|
||||
|
@ -137,8 +139,6 @@ testImports:
|
|||
- log
|
||||
- name: github.com/mattn/go-colorable
|
||||
version: 9056b7a9f2d1f2d96498d6d146acd1f9d5ed3d59
|
||||
- name: github.com/mattn/go-isatty
|
||||
version: 56b76bdf51f7708750eac80fa38b952bb9f32639
|
||||
- name: github.com/pmezard/go-difflib
|
||||
version: 792786c7400a136282c1664665ae0a8db921c6c2
|
||||
subpackages:
|
||||
|
|
|
@ -4,6 +4,7 @@ import:
|
|||
- package: github.com/asdine/storm
|
||||
- package: github.com/fvbock/endless
|
||||
- package: github.com/gin-gonic/gin
|
||||
version: ^1.1.4
|
||||
- package: github.com/google/go-gcm
|
||||
- package: github.com/sideshow/apns2
|
||||
subpackages:
|
||||
|
@ -17,6 +18,8 @@ import:
|
|||
- package: gopkg.in/appleboy/gin-status-api.v1
|
||||
- package: gopkg.in/redis.v4
|
||||
- package: gopkg.in/yaml.v2
|
||||
- package: github.com/mattn/go-isatty
|
||||
version: ^0.0.1
|
||||
testImport:
|
||||
- package: github.com/buger/jsonparser
|
||||
- package: github.com/stretchr/testify
|
||||
|
|
|
@ -4,10 +4,12 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mattn/go-isatty"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -54,6 +56,12 @@ type LogPushEntry struct {
|
|||
Category string `json:"category,omitempty"`
|
||||
}
|
||||
|
||||
var isTerm bool
|
||||
|
||||
func init() {
|
||||
isTerm = isatty.IsTerminal(os.Stdout.Fd())
|
||||
}
|
||||
|
||||
// InitLog use for initial log module
|
||||
func InitLog() error {
|
||||
|
||||
|
@ -145,9 +153,15 @@ func LogRequest(uri string, method string, ip string, contentType string, agent
|
|||
|
||||
output = string(logJSON)
|
||||
} else {
|
||||
var headerColor string
|
||||
|
||||
if isTerm {
|
||||
headerColor = magenta
|
||||
}
|
||||
|
||||
// format is string
|
||||
output = fmt.Sprintf("|%s header %s| %s %s %s %s %s",
|
||||
magenta, reset,
|
||||
headerColor, reset,
|
||||
log.Method,
|
||||
log.URI,
|
||||
log.IP,
|
||||
|
@ -203,8 +217,10 @@ func hideToken(token string, markLen int) string {
|
|||
func LogPush(status, token string, req PushNotification, errPush error) {
|
||||
var plat, platColor, output string
|
||||
|
||||
if isTerm {
|
||||
platColor = colorForPlatForm(req.Platform)
|
||||
plat = typeForPlatForm(req.Platform)
|
||||
}
|
||||
|
||||
errMsg := ""
|
||||
if errPush != nil {
|
||||
|
@ -228,17 +244,26 @@ func LogPush(status, token string, req PushNotification, errPush error) {
|
|||
|
||||
output = string(logJSON)
|
||||
} else {
|
||||
var typeColor string
|
||||
switch status {
|
||||
case SucceededPush:
|
||||
if isTerm {
|
||||
typeColor = green
|
||||
}
|
||||
|
||||
output = fmt.Sprintf("|%s %s %s| %s%s%s [%s] %s",
|
||||
green, log.Type, reset,
|
||||
typeColor, log.Type, reset,
|
||||
platColor, log.Platform, reset,
|
||||
log.Token,
|
||||
log.Message,
|
||||
)
|
||||
case FailedPush:
|
||||
if isTerm {
|
||||
typeColor = red
|
||||
}
|
||||
|
||||
output = fmt.Sprintf("|%s %s %s| %s%s%s [%s] | %s | Error Message: %s",
|
||||
red, log.Type, reset,
|
||||
typeColor, log.Type, reset,
|
||||
platColor, log.Platform, reset,
|
||||
log.Token,
|
||||
log.Message,
|
||||
|
|
Loading…
Reference in New Issue