logging

package module
v0.0.0-...-d412952 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: Apache-2.0 Imports: 17 Imported by: 13

README

logging

package main

import (
    "errors"
    "net/http"
    "github.com/peramic/logging"
    app "./go"
)

var log *logging.Logger

func main() {
    log = logging.GetLogger("myApp")

    app.AddRoutes(logging.LogRoutes)

    log.Info("Server started")
    log.Error("Something got wrong")
    //log actual error true
    err:=errors.New("erors")
    log.WithError(err).Fatal("Something got wrong")
    router := app.NewRouter()

    log.Fatal(http.ListenAndServe(":8080", router))
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LogRoutes = utils.Routes{

	utils.Route{
		Name:        "GetLogLevels",
		Method:      "GET",
		Pattern:     "/rest/log/levels",
		HandlerFunc: getLogLevels,
	},
	utils.Route{
		Name:        "GetLogTargets",
		Method:      "GET",
		Pattern:     "/rest/log/targets",
		HandlerFunc: getLogTargets,
	},
	utils.Route{
		Name:        "GetLevel",
		Method:      "GET",
		Pattern:     "/rest/log/{target}/level",
		HandlerFunc: getLogLevel,
	},
	utils.Route{
		Name:        "SetLogLevel",
		Method:      "PUT",
		Pattern:     "/rest/log/{target}/level",
		HandlerFunc: setLogLevel,
	},
	utils.Route{
		Name:        "GetLogSize",
		Method:      "GET",
		Pattern:     "/rest/log/{target}/{level}",
		HandlerFunc: getLogSize,
	},
	utils.Route{
		Name:        "GetLogEntries",
		Method:      "GET",
		Pattern:     "/rest/log/{target}/{level}/{limit}/{offset}",
		HandlerFunc: getLogEntries,
	},
	utils.Route{
		Name:        "DeleteLogEntries",
		Method:      "DELETE",
		Pattern:     "/rest/log/{target}",
		HandlerFunc: deleteLogEntries,
	},
	utils.Route{
		Name:        "GetLogFile",
		Method:      "GET",
		Pattern:     "/rest/log/{target}/{level}/export",
		HandlerFunc: getLogFile,
	},
}

LogRoutes routes

Functions

func Close

func Close()

Close close the database connection

func Notify

func Notify(topic string, message Message)

Notify used for notification only

func SetHost

func SetHost(name string)

SetHost sets the host name for routes shoud be called first

Types

type LogEntry

type LogEntry struct {
	ID           int    `json:"id"`
	Time         int64  `json:"time"`
	Host         string `json:"host"`
	TargetName   string `json:"targetName"`
	SourceMethod string `json:"sourceMethod"`
	Level        string `json:"level"`
	Message      string `json:"message"`
	Thrown       string `json:"thrown"`
}

LogEntry log entry structure

type Logger

type Logger struct {
	*logrus.Logger
	// contains filtered or unexported fields
}

Logger custom logger

func GetLogger

func GetLogger(name string) *Logger

GetLogger returns an instance of logger

type Message

type Message struct {
	Ref string `json:"ref,omitempty"`
	// PENDING, SUCCESS, FAILURE
	Status string `json:"status,omitempty"`
	Text   string `json:"text,omitempty"`
}

Message notification message

type Target

type Target struct {
	Name  string `json:"name"`
	Label string `json:"label"`
}

Target logging target

type TargetMessage

type TargetMessage struct {
	Target string `json:"target"`
	Host   string `json:"host"`
}

TargetMessage target mqtt message

Jump to

Keyboard shortcuts

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