README

Logging

Small Golang package to output alternative logs

Installation
go get code.afis.me/logging
Example
package main

import (
 "code.afis.me/logging"
)

var logger *logging.Logger
var maxlogsize int64 = 10000

func init() {
 logger := logging.NewLogger("test", []string{"/code.afis.me/logging/"})
 // if you store logs
 store := logging.NewLogsStore(maxlogsize)
 logger.OutputHandler = func(ps *logging.PushLogs) {
  store.Store(true, ps.ID, ps)
 }
 // end if you store logs
}


func main() {
  
 err := fmt.Errorf("Hello")

 // just display error output
 logger.Error(err)

 // if error not nil, then run os.Exit(2)
 logger.Error(err).Quit(err)

 logger.Debug("Hello from golang")
 logger.Warning("Hello from golang")
 logger.Success("Hello from golang")

}
Expand ▾ Collapse ▴

Documentation

Index

Constants

View Source
const (
	// LOGDEBUG -
	LOGDEBUG = iota
	// LOGWARNING -
	LOGWARNING
	// LOGERROR -
	LOGERROR
	// LOGSUCCESS -
	LOGSUCCESS
	// LOGNOTICE -
	LOGNOTICE
)
View Source
const (
	// LEVELDEBUG -
	LEVELDEBUG = iota
	// LEVELWARNING -
	LEVELWARNING
	// LEVELERROR -
	LEVELERROR
	// LEVELNOTICE -
	LEVELNOTICE
)

Variables

This section is empty.

Functions

func GetLevelLogName

func GetLevelLogName(level int) (lv string)

    GetLevelLogName -

    func OutputHandlerConsole

    func OutputHandlerConsole(ps *PushLogs)

      OutputHandlerConsole -

      func ParsingLogs

      func ParsingLogs(ps *PushLogs, opt ParsingOption) (raw string)

        ParsingLogs -

        Types

        type LogStore

        type LogStore struct {
        	Counting  int64
        	OnNewLogs func(value interface{})
        	sync.RWMutex
        	// contains filtered or unexported fields
        }

          LogStore -

          func NewLogsStore

          func NewLogsStore(maxlogsize int64) *LogStore

            NewLogsStore -

            func (*LogStore) ClearLogs

            func (rm *LogStore) ClearLogs(id string, ts []int64)

              ClearLogs -

              func (*LogStore) Count

              func (rm *LogStore) Count() int64

                Count -

                func (*LogStore) LoadAll

                func (rm *LogStore) LoadAll(lid string, start int64, limit int) (value []LogsValue)

                  LoadAll -

                  func (*LogStore) RemoveByID

                  func (rm *LogStore) RemoveByID(lid string)

                    RemoveByID -

                    func (*LogStore) Reset

                    func (rm *LogStore) Reset()

                      Reset -

                      func (*LogStore) Store

                      func (rm *LogStore) Store(printWhenStore bool, key string, value interface{})

                        Store -

                        type Logger

                        type Logger struct {
                        	Name          string
                        	Splitter      []string
                        	LogLevel      int
                        	OutputHandler func(*PushLogs)
                        }

                          Logger -

                          func NewLogger

                          func NewLogger(name string, spli interface{}) *Logger

                            NewLogger -

                            func (*Logger) AlwaysShow

                            func (cc *Logger) AlwaysShow(level int, msg string) *Logger

                              AlwaysShow -

                              func (*Logger) CreateHash

                              func (cc *Logger) CreateHash(key string) string

                                CreateHash -

                                func (*Logger) Debug

                                func (cc *Logger) Debug(msg string) *Logger

                                  Debug -

                                  func (*Logger) Error

                                  func (cc *Logger) Error(err error) *Logger

                                  func (*Logger) GenerateUUID

                                  func (cc *Logger) GenerateUUID() string

                                    GenerateUUID -

                                    func (*Logger) MakeID

                                    func (cc *Logger) MakeID() string

                                      MakeID -

                                      func (*Logger) Notice

                                      func (cc *Logger) Notice(msg string) *Logger

                                        Notice -

                                        func (*Logger) Output

                                        func (cc *Logger) Output(ps *PushLogs) *Logger

                                          Output -

                                          func (*Logger) Quit

                                          func (cc *Logger) Quit(err error) error

                                            Quit -

                                            func (*Logger) SetLevel

                                            func (cc *Logger) SetLevel(ps int) *Logger

                                              SetLevel -

                                              func (*Logger) Success

                                              func (cc *Logger) Success(msg string) *Logger

                                                Success -

                                                func (*Logger) Warning

                                                func (cc *Logger) Warning(msg string) *Logger

                                                  Warning -

                                                  type LogsMap

                                                  type LogsMap map[time.Time]interface{}

                                                    LogsMap -

                                                    type LogsValue

                                                    type LogsValue struct {
                                                    	ID    string
                                                    	Time  time.Time
                                                    	Value interface{}
                                                    }

                                                      LogsValue -

                                                      type ParsingOption

                                                      type ParsingOption struct {
                                                      	Name func(string) string
                                                      }

                                                        ParsingOption -

                                                        type PushLogs

                                                        type PushLogs struct {
                                                        	ID         string    `json:"id"`
                                                        	Origin     string    `json:"origin"`
                                                        	Name       string    `json:"name"`
                                                        	Time       time.Time `json:"time"`
                                                        	Level      int       `json:"level"`
                                                        	LongFile   string    `json:"longFile"`
                                                        	ShortFile  string    `json:"shortFile"`
                                                        	LineNumber int       `json:"lineNumber"`
                                                        	Message    string    `json:"message"`
                                                        }

                                                          PushLogs -

                                                          Source Files