logging

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Copyright (c) 2025 Chakib Ben Ziane <contact@blob42.xyz> and [`gosuki` contributors](https://github.com/blob42/gosuki/graphs/contributors). All rights reserved.

SPDX-License-Identifier: AGPL-3.0-or-later

This file is part of GoSuki.

GoSuki is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

GoSuki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with gosuki. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	Release = iota
	Dev
	Silent = math.MaxInt
)

log level shortcuts

View Source
const EnvGosukiDebug = "GOSUKI_DEBUG"
View Source
const TraceLevel = log.DebugLevel - 1

Variables

View Source
var (
	ErrUnknownLevel  = errors.New("unknown debug level")
	ErrHelpQuit      = errors.New("help quit")
	ErrParseSubLevel = errors.New("cannot parse unit level")
)

errors

View Source
var (
	//RELEASE: Change to Release for release mode
	LoggingMode = Dev
	TUIMode     bool
	SilentMode  bool
)
View Source
var DebugFlag = &cli.StringFlag{
	Name:        "debug",
	Usage:       debugHelp,
	DefaultText: "warn",
	Sources:     cli.EnvVars(EnvGosukiDebug),
	Action: func(_ context.Context, _ *cli.Command, val string) error {
		if SilentMode {
			SetLevel(Silent)
		}
		return ParseDebugLevels(val)
	},
}
View Source
var (
	DefaultLogLevels = map[int]log.Level{
		Release: log.WarnLevel,
		Dev:     log.DebugLevel,
	}
)
View Source
var (
	Stdout io.Writer
)

log level strings

Functions

func FDebugf

func FDebugf(fileName, format string, args ...any)

flog is a convenience function for logging messages to a specified file logger.

func ParseDebugLevels added in v1.2.0

func ParseDebugLevels(val string) error

func SetLevel added in v1.2.0

func SetLevel(lvl log.Level)

func SetTUI

func SetTUI(output io.Writer)

Sets the logging into TUI mode.

func SetUnitLevel added in v1.2.0

func SetUnitLevel(u string, lvl log.Level)

Types

type Logger added in v1.2.0

type Logger struct {
	*log.Logger
}

func GetLogger

func GetLogger(module string) *Logger

func NewFileLogger

func NewFileLogger(fileName string) (*Logger, error)

NewFileLogger creates a new logger that outputs to a specified file.

func NewLogger added in v1.2.0

func NewLogger(w io.Writer) *Logger

func (*Logger) Trace added in v1.2.0

func (l *Logger) Trace(msg string, args ...any)

func (*Logger) Tracef added in v1.2.0

func (l *Logger) Tracef(format string, args ...any)

func (*Logger) With added in v1.2.0

func (l *Logger) With(keyvals ...any) *Logger

func (*Logger) WithPrefix added in v1.2.0

func (l *Logger) WithPrefix(prefix string) *Logger

type TailBuffer

type TailBuffer struct {
	// contains filtered or unexported fields
}

TailBuffer is a struct that maintains a buffer of the last N lines written to it.

func NewTailBuffer

func NewTailBuffer(n int) *TailBuffer

func (*TailBuffer) Lines

func (t *TailBuffer) Lines() []string

func (*TailBuffer) Write

func (t *TailBuffer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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