util

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	LOG_LEVEL_DEBUG = "DEBUG"
	LOG_LEVEL_INFO  = "INFO"
	LOG_LEVEL_WARN  = "WARN"
	LOG_LEVEL_ERROR = "ERROR"
)

Variables

This section is empty.

Functions

func FormatCount added in v0.0.2

func FormatCount(count int, unit CountUnit) string
Example
package main

import (
	"fmt"

	"github.com/OutOfBedlam/tine/util"
)

func main() {
	fmt.Println(util.FormatCount(0, util.CountUnitLines))
	fmt.Println(util.FormatCount(1, util.CountUnitLines))
	fmt.Println(util.FormatCount(2, util.CountUnitLines))
}
Output:

0 lines
1 line
2 lines

func FormatFileSize

func FormatFileSize(bytes int64) string

ByteSize returns a human-readable byte size string.

Example
package main

import (
	"fmt"

	"github.com/OutOfBedlam/tine/util"
)

func main() {
	fmt.Println(util.FormatFileSize(0))
	fmt.Println(util.FormatFileSize(1))
	fmt.Println(util.FormatFileSize(1024))
	fmt.Println(util.FormatFileSize(1024 * 1024))
	fmt.Println(util.FormatFileSize(1024 * 1024 * 1024))
	fmt.Println(util.FormatFileSize(1024 * 1024 * 1024 * 1024))
	fmt.Println(util.FormatFileSize(1024 * 1024 * 1024 * 1024 * 1024))
}
Output:

0B
1B
1.00KB
1.00MB
1.00GB
1.00TB
1.00PB

func FormatFileSizeInt

func FormatFileSizeInt(bytes int) string

func NewLogger

func NewLogger(conf LogConfig) *slog.Logger
Example
// This example demonstrates how to create a new logger with different log levels.
// The logger is configured to write to a file and the log level is set to INFO.
conf := LogConfig{
	Filename: "-", // "-" writes to stdout, "" discard logging, otherwise writes to a file
	Level:    LOG_LEVEL_INFO,
}
logger := NewLogger(conf)
logger.Debug("This is a debug message")
logger.Info("This is an info message")
logger.Warn("This is a warning message")
logger.Error("This is an error message")

Types

type CountUnit added in v0.0.2

type CountUnit [2]string
var (
	CountUnitLines CountUnit = [2]string{"line", "lines"}
)

type LogConfig

type LogConfig struct {
	Filename   string `toml:"filename"`
	Level      string `toml:"level"`
	MaxSize    int    `toml:"max_size"`
	MaxAge     int    `toml:"max_age"`
	MaxBackups int    `toml:"max_backups"`
	Compress   bool   `toml:"compress,omitempty"`
	Chown      string `toml:"chown,omitempty"`
}

Jump to

Keyboard shortcuts

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