dlog

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: BSD-3-Clause Imports: 6 Imported by: 15

README

====================
 Standard Logger Ex
====================

.. image:: https://pkg.go.dev/badge/github.com/rusq/dlog.svg
   :target: https://pkg.go.dev/github.com/rusq/dlog

What is this?
=============

This is a simple wrapper around the standard go runtime logger with only one
goal:

* ADD DEBUG OUTPUT FUNCTIONS.

Functions that are available for the caller:

* All those in "log" AND
* Debug
* Debugf
* Debugln

On the package base level these functions will print output only if the
``DEBUG`` environment variable is present and have some non-empty value.

Otherwise, one can construct a new logger::

  func New(out io.Writer, prefix string, flag int, debug bool) *Logger

for the flags, one could use the values from the standard logger.


Usage
=====

Import it in your project replacing "log" import entry:

.. code:: go

  import (
    log "github.com/rusq/dlog"
  )

Use:

.. code:: go

   log.Debug("hello debug!")

Check if debug is enabled:

.. code:: go

   log.IsDebug()


Documentation

Overview

Package log is a wrapper around standard go logger that adds the debug output functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

func Debugf

func Debugf(format string, v ...interface{})

func Debugln

func Debugln(v ...interface{})

func Fatal

func Fatal(v ...interface{})

Fatal is equivalent to Print() followed by a call to os.Exit(1).

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

func Fatalln

func Fatalln(v ...interface{})

Fatalln is equivalent to Println() followed by a call to os.Exit(1).

func Flags

func Flags() int

Flags returns the output flags for the standard logger. The flag bits are Ldate, Ltime, and so on.

func IsDebug added in v1.4.0

func IsDebug() bool

IsDebug returns true if the debugging output is enabled.

func NewContext added in v1.3.0

func NewContext(ctx context.Context, l *Logger) context.Context

NewContext returns a new Context that has logger attached.

func Output

func Output(calldepth int, s string) error

Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is the count of the number of frames to skip when computing the file name and line number if Llongfile or Lshortfile is set; a value of 1 will print the details for the caller of Output.

func Panic

func Panic(v ...interface{})

Panic is equivalent to Print() followed by a call to panic().

func Panicf

func Panicf(format string, v ...interface{})

Panicf is equivalent to Printf() followed by a call to panic().

func Panicln

func Panicln(v ...interface{})

Panicln is equivalent to Println() followed by a call to panic().

func Prefix

func Prefix() string

Prefix returns the output prefix for the standard logger.

func Print

func Print(v ...interface{})

Print calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Print.

func Printf

func Printf(format string, v ...interface{})

Printf calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Printf.

func Println

func Println(v ...interface{})

Println calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Println.

func SetDebug added in v1.1.0

func SetDebug(b bool)

SetDebug sets/resets the debugging output.

func SetFlags

func SetFlags(flag int)

SetFlags sets the output flags for the standard logger. The flag bits are Ldate, Ltime, and so on.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output destination for the standard logger.

func SetPrefix

func SetPrefix(prefix string)

SetPrefix sets the output prefix for the standard logger.

func Writer

func Writer() io.Writer

Writer returns the output destination for the standard logger.

Types

type Logger

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

func FromContext added in v1.3.0

func FromContext(ctx context.Context) *Logger

FromContext returns the Logger value stored in ctx, if any. If no Logger is present, it returns the standard logger instance.

func New

func New(out io.Writer, prefix string, flag int, debug bool) *Logger

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

func (*Logger) Debugln

func (l *Logger) Debugln(v ...interface{})

func (*Logger) IsDebug added in v1.4.0

func (l *Logger) IsDebug() bool

IsDebug returns true if the debugging output is enabled.

func (*Logger) Panic added in v1.3.1

func (l *Logger) Panic(v ...interface{})

Panic is equivalent to Print() followed by a call to panic().

func (*Logger) Panicf added in v1.3.1

func (l *Logger) Panicf(format string, v ...interface{})

Panicf is equivalent to Printf() followed by a call to panic().

func (*Logger) Panicln added in v1.3.1

func (l *Logger) Panicln(v ...interface{})

Panicln is equivalent to Println() followed by a call to panic().

func (*Logger) SetDebug added in v1.1.0

func (l *Logger) SetDebug(b bool)

SetDebug sets/resets the debugging output.

Jump to

Keyboard shortcuts

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