logger

package
v0.0.0-...-4973d3c Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FilterByID                = "id = ?"
	StrRefreshMovies          = "Refresh Movies"
	StrRefreshMoviesInc       = "Refresh Movies Incremental"
	StrRefreshSeries          = "Refresh Series"
	StrRefreshSeriesInc       = "Refresh Series Incremental"
	StrDebug                  = "debug"
	StrDate                   = "date"
	StrID                     = "id"
	StrURL                    = "Url"
	StrQuery                  = "Query"
	StrJob                    = "Job"
	StrJobLower               = "job"
	StrFile                   = "File"
	StrPath                   = "Path"
	StrListname               = "Listname"
	StrImdb                   = "imdb"
	StrTitle                  = "Title"
	StrPriority               = "Priority"
	StrSearchMissingInc       = "searchmissinginc"
	StrSearchMissingFull      = "searchmissingfull"
	StrSearchMissingIncTitle  = "searchmissinginctitle"
	StrSearchMissingFullTitle = "searchmissingfulltitle"
	StrSearchUpgradeInc       = "searchupgradeinc"
	StrSearchUpgradeFull      = "searchupgradefull"
	StrSearchUpgradeIncTitle  = "searchupgradeinctitle"
	StrSearchUpgradeFullTitle = "searchupgradefulltitle"
	StrStructure              = "structure"
	StrCheckMissing           = "checkmissing"
	StrCheckMissingFlag       = "checkmissingflag"
	StrUpgradeFlag            = "checkupgradeflag"
	StrReachedFlag            = "checkreachedflag"
	StrClearHistory           = "clearhistory"
	StrRssSeasonsAll          = "rssseasonsall"
	StrSerie                  = "serie"
	StrRssSeasons             = "rssseasons"
	StrRss                    = "rss"
	Underscore                = "_"
	StrTvdb                   = "tvdb"
	StrTt                     = "tt"
	StrSeries                 = "series"
	CacheDBMedia              = "CacheDBMedia"
	DBCountDBMedia            = "DBCountDBMedia"
	DBCacheDBMedia            = "DBCacheDBMedia"
	CacheMedia                = "CacheMedia"
	DBCountMedia              = "DBCountMedia"
	DBCacheMedia              = "DBCacheMedia"
	CacheHistoryTitle         = "CacheHistoryTitle"
	CacheHistoryUrl           = "CacheHistoryUrl"
	DBHistoriesUrl            = "DBHistoriesUrl"
	DBHistoriesTitle          = "DBHistoriesTitle"
	DBCountHistoriesUrl       = "DBCountHistoriesUrl"
	DBCountHistoriesTitle     = "DBCountHistoriesTitle"
	CacheMediaTitles          = "CacheMediaTitles"
	DBCountDBTitles           = "DBCountDBTitles"
	DBCacheDBTitles           = "DBCacheDBTitles"
	CacheFiles                = "CacheFiles"
	DBCountFiles              = "DBCountFiles"
	DBCacheFiles              = "DBCacheFiles"
	CacheUnmatched            = "CacheUnmatched"
	DBCountUnmatched          = "DBCountUnmatched"
	DBCacheUnmatched          = "DBCacheUnmatched"
	DBCountFilesLocation      = "DBCountFilesLocation"
	DBCountUnmatchedPath      = "DBCountUnmatchedPath"
	DBCountDBTitlesDBID       = "DBCountDBTitlesDBID"
	DBDistinctDBTitlesDBID    = "DBDistinctDBTitlesDBID"
	DBMediaTitlesID           = "DBMediaTitlesID"
	DBFilesQuality            = "DBFilesQuality"
	DBCountFilesByList        = "DBCountFilesByList"
	DBLocationFilesByList     = "DBLocationFilesByList"
	DBIDsFilesByLocation      = "DBIDsFilesByLocation"
	DBCountFilesByMediaID     = "DBCountFilesByMediaID"
	DBCountFilesByLocation    = "DBCountFilesByLocation"
	TableFiles                = "TableFiles"
	TableMedia                = "TableMedia"
	DBCountMediaByList        = "DBCountMediaByList"
	DBIDMissingMediaByList    = "DBIDMissingMediaByList"
	DBUpdateMissing           = "DBUpdateMissing"
	DBListnameByMediaID       = "DBListnameByMediaID"
	DBRootPathFromMediaID     = "DBRootPathFromMediaID"
	DBDeleteFileByIDLocation  = "DBDeleteFileByIDLocation"
	DBCountHistoriesByTitle   = "DBCountHistoriesByTitle"
	DBCountHistoriesByUrl     = "DBCountHistoriesByUrl"
	DBLocationIDFilesByID     = "DBLocationIDFilesByID"
	DBFilePrioFilesByID       = "DBFilePrioFilesByID"
	UpdateMediaLastscan       = "UpdateMediaLastscan"
	DBQualityMediaByID        = "DBQualityMediaByID"
	SearchGenSelect           = "SearchGenSelect"
	SearchGenTable            = "SearchGenTable"
	SearchGenMissing          = "SearchGenMissing"
	SearchGenMissingEnd       = "SearchGenMissingEnd"
	SearchGenReached          = "SearchGenReached"
	SearchGenLastScan         = "SearchGenLastScan"
	SearchGenDate             = "SearchGenDate"
	SearchGenOrder            = "SearchGenOrder"

	CacheMovie              = "CacheMovie"
	CacheSeries             = "CacheSeries"
	CacheDBMovie            = "CacheDBMovie"
	CacheDBSeries           = "CacheDBSeries"
	CacheDBSeriesAlt        = "CacheDBSeriesAlt"
	CacheTitlesMovie        = "CacheTitlesMovie"
	CacheUnmatchedMovie     = "CacheUnmatchedMovie"
	CacheUnmatchedSeries    = "CacheUnmatchedSeries"
	CacheFilesMovie         = "CacheFilesMovie"
	CacheFilesSeries        = "CacheFilesSeries"
	CacheHistoryUrlMovie    = "CacheHistoryUrlMovie"
	CacheHistoryTitleMovie  = "CacheHistoryTitleMovie"
	CacheHistoryUrlSeries   = "CacheHistoryUrlSeries"
	CacheHistoryTitleSeries = "CacheHistoryTitleSeries"
)

Variables

View Source
var (
	V0          uint = 0
	StrFeeds         = "feeds"
	StrData          = "data"
	StrDataFull      = "datafull"
	StrMovie         = "movie"

	Log zerolog.Logger

	//diacriticsReplacer   = strings.NewReplacer("ä", "ae", "ö", "oe", "ü", "ue", "Ä", "Ae", "Ö", "Oe", "Ü", "Ue", "ß", "ss")
	//pathReplacer         = strings.NewReplacer(":", "", "*", "", "?", "", "\"", "", "<", "", ">", "", "|", "")
	ErrNoID              = errors.New("no id")
	ErrNoFiles           = errors.New("no files")
	ErrNotFound          = errors.New("not found")
	Errwrongtype         = errors.New("wrong type")
	ErrRuntime           = errors.New("wrong runtime")
	ErrNotAllowed        = errors.New("not allowed")
	ErrLowerQuality      = errors.New("lower quality")
	ErrOther             = errors.New("other error")
	ErrDisabled          = errors.New("disabled")
	ErrToWait            = errors.New("please wait")
	ErrTooSmall          = errors.New("too small")
	ErrDailyLimit        = errors.New("daily limit reached")
	Errnoresults         = errors.New("no results")
	ErrNotFoundDbmovie   = errors.New("dbmovie not found")
	ErrNotFoundMovie     = errors.New("movie not found")
	ErrNotFoundDbserie   = errors.New("dbserie not found")
	ErrNotFoundSerie     = errors.New("serie not found")
	ErrNotEnabled        = errors.New("not enabled")
	ErrCfgpNotFound      = errors.New("cfgpstr not found")
	ErrNotFoundDBEpisode = errors.New("dbepisode not found")
	ErrNotFoundEpisode   = errors.New("episode not found")
	ErrListnameEmpty     = errors.New("listname empty")
	ErrTvdbEmpty         = errors.New("tvdb empty")
	ErrImdbEmpty         = errors.New("imdb empty")
	ErrSearchvarEmpty    = errors.New("searchvar empty")
	ErrTracksEmpty       = errors.New("tracks empty")
	PlBuffer             = pool.NewPool(100, 0, func(b *bytes.Buffer) {}, func(b *bytes.Buffer) {
		b.Reset()
	})
)

Functions

func AddImdbPrefix

func AddImdbPrefix(str string) string

AddImdbPrefix prepends the imdb prefix if it doesn't already exist.

func AddTvdbPrefix

func AddTvdbPrefix(str string) string

AddTvdbPrefix prepends the tvdb prefix if it doesn't already exist.

func BuilderAddInt

func BuilderAddInt(bld *bytes.Buffer, i int)

BuilderAddInt writes the string representation of the given int to the given bytes.Buffer.

func BuilderAddUint

func BuilderAddUint(bld *bytes.Buffer, i uint)

BuilderAddUint writes the string representation of the unsigned integer i to the buffer bld.

func ByteReplaceWithByte

func ByteReplaceWithByte(s []byte, r rune, t rune) []byte

StringReplaceWith replaces all occurrences of the rune r in s with the rune t. It returns a new string with the replacements.

func Contains

func Contains[S ~[]E, E comparable](s S, v E) bool

Contains reports whether v is contained in s.

func ContainsI

func ContainsI(a string, b string) bool

ContainsI checks if string a contains string b, ignoring case. It first checks for a direct match with strings.Contains. If not found, it does a case-insensitive search by looping through a and comparing substrings with EqualFold.

func ContainsInt

func ContainsInt(a string, b int) bool

ContainsInt checks if the string a contains the string representation of the integer b. It converts b to a string using strconv.Itoa and calls strings.Contains to check for a match.

func DiacriticsReplacer

func DiacriticsReplacer(s string) string

diacriticsReplacer replaces diacritic marks in the input string s with their ASCII equivalents, based on the provided diacriticsmap. It calls the replacer function to perform the replacements.

func GetStringsMap

func GetStringsMap(useseries bool, typestr string) string

GetStringsMap returns the map of strings for the given type based on whether to use the series or movies map. If useseries is true, it returns the mapstringsseries map, otherwise it returns the mapstringsmovies map.

func GetTimeFormat

func GetTimeFormat() string

GetTimeFormat returns the time format string used for formatting logs. This allows checking the current time format.

func GetTimeZone

func GetTimeZone() *time.Location

GetTimeZone returns a pointer to the time.Location representing the timezone used for formatting logs. This allows checking the current timezone.

func Getrootpath

func Getrootpath(foldername string) string

Getrootpath returns the root path of the given folder name by splitting on '/' or '\' and trimming any trailing slashes. If no slashes, it just trims trailing slashes.

func Getstringarrlength

func Getstringarrlength(elems []string) int

Getstringarrlength returns the total length of all strings in the given string slice elems. It iterates through the slice and sums the individual string lengths.

func HasPrefixI

func HasPrefixI(s, prefix string) bool

HasPrefixI checks if string s starts with prefix, ignoring case. It first checks for a direct match with strings.HasPrefix. If not found, it does a case-insensitive check by comparing the substring of s from 0 to len(prefix) with prefix using EqualFold.

func HasSuffixI

func HasSuffixI(s, suffix string) bool

HasSuffixI checks if string s ends with suffix, ignoring case. It first checks for a direct match with strings.HasSuffix. If not found, it does a case-insensitive check by comparing the substring of s from len(s)-len(suffix) to len(s) with suffix using EqualFold.

func IndexI

func IndexI(a string, b string) int

IndexI searches for the first case-insensitive instance of b in a. It returns the index of the first match, or -1 if no match is found.

func IndexILast

func IndexILast(a string, b string) int

IndexILast searches for the last case-insensitive instance of b in a. It returns the index of the last match, or -1 if no match is found.

func InitLogger

func InitLogger(config Config)

InitLogger initializes the global logger based on the provided Config. It sets the log level, output format, rotation options, etc.

func JoinStrings

func JoinStrings(elems ...string) string

JoinStrings concatenates any number of strings together. It is optimized to avoid unnecessary allocations when there are few elements.

func LogDynamic

func LogDynamic(typev string, msg string, fields ...LogField)

LogDynamic logs a message with dynamic log level and arbitrary fields. It takes the log level type as the first argument, followed by the log message, and finally any number of LogField structs containing the key-value pairs. It allows logging with different levels and custom fields in a flexible way. For typev use one of the following: "info", "debug", "error", "fatal", "warn", "panic"

func LogDynamicSlice

func LogDynamicSlice(typev string, msg string, staticfields []LogField, fields ...LogField)

LogDynamicSlice logs a message with dynamic fields and static fields. It allows specifying the log level, message, static fields, and dynamic fields. The static fields are logged on every call, while the dynamic fields can vary per call. For typev use one of the following: "info", "debug", "error", "fatal", "warn", "panic"

func ParseJson

func ParseJson(r io.Reader, obj any) error

ParseJson decodes the JSON encoded data from the provided reader into the given object. Returns any error encountered during decoding.

func ParseStringTemplate

func ParseStringTemplate(message string, messagedata any) (bool, string)

ParseStringTemplate parses a text/template string into a template.Template, caches it, and executes it with the given data. It returns the executed template string and any error encountered.

func ParseToml

func ParseToml(r io.Reader, obj any) error

ParseToml decodes the TOML encoded data from the provided reader into the given object. Returns any error encountered during decoding.

func Path

func Path(s string, allowslash bool) string

Path sanitizes the given string by cleaning it with path.Clean, unquoting and unescaping it, optionally removing slashes, and replacing invalid characters. It returns the cleaned path string.

func SlicesContainsI

func SlicesContainsI(s []string, v string) bool

Contains reports whether v is present in s - case insensitive.

func SlicesContainsPart2I

func SlicesContainsPart2I(s []string, v string) bool

Contains reports whether v is contained in s - case insensitive.

func SplitByFullP

func SplitByFullP(str string, splitby rune) string

SplitByFullP splits a string into two parts by the first occurrence of the split rune. It returns the part before the split. If the split rune is not found, it returns the original string.

func SplitByLR

func SplitByLR(str string, splitby byte) (string, string)

SplitByLR splits str into left and right substrings by the last occurrence of splitby byte. It returns the left substring before the split byte and the right substring after. If splitby byte is not found or invalid, an empty string and the original str are returned.

func StringRemoveAllRunes

func StringRemoveAllRunes(s string, r rune) string

StringRemoveAllRunes removes all occurrences of the rune r from s.

func StringRemoveAllRunesMulti

func StringRemoveAllRunesMulti(s string, r ...rune) string

StringRemoveAllRunes removes all occurrences of the rune r from s.

func StringReplaceWith

func StringReplaceWith(s string, r rune, t rune) string

StringReplaceWith replaces all occurrences of the rune r in s with the rune t. It returns a new string with the replacements.

func StringReplaceWithByte

func StringReplaceWithByte(s string, r rune, t rune) []byte

StringReplaceWith replaces all occurrences of the rune r in s with the rune t. It returns a new string with the replacements.

func StringToFileMode

func StringToFileMode(s string) fs.FileMode

StringToFileMode converts a string representing a file mode in octal to a uint32. It returns 0 if the string is empty or cannot be parsed.

func StringToInt

func StringToInt(s string) int

StringToInt converts the given string to an int. It uses stringToUint64 to convert to a uint64 first, then converts the result to an int.

func StringToInt64

func StringToInt64(s string) int64

StringToInt64 converts the given string to an int64. It uses stringToUint64 to convert to a uint64 first, then converts the result to an int64.

func StringToSlug

func StringToSlug(instr string) string

StringToSlug converts the given string to a slug format by replacing unwanted characters, transliterating accented characters, replacing multiple hyphens with a single hyphen, and trimming leading/trailing hyphens.

func TimeGetNow

func TimeGetNow() time.Time

TimeGetNow returns the current time in the time zone specified by the global timeZone variable.

func TrimStringInclAfterString

func TrimStringInclAfterString(s string, search string) string

TrimStringInclAfterString truncates the given string s after the first occurrence of the search string. It returns the truncated string.

func URLJoinPath

func URLJoinPath(base string, elem ...string) string

URLJoinPath joins a base URL path with any number of path elements. It uses url.JoinPath under the hood and discards any errors.

func UnquoteUnescape

func UnquoteUnescape(s string) string

UnquoteUnescape unquotes a quoted string and unescapes HTML entities. It first tries to unquote the string as a quoted string literal. If that succeeds and the unquoted string contains HTML entities, it unescapes the HTML entities. If unquoting fails, it just unescapes any HTML entities in the original string.

Types

type Config

type Config struct {
	// LogLevel sets the minimum enabled logging level. Valid levels are
	// "debug", "info", "warn", and "error".
	LogLevel string

	// LogFileSize is the maximum size in megabytes of the log file before it gets
	// rotated. It defaults to 10 megabytes.
	LogFileSize int

	// LogFileCount is the maximum number of old log files to retain.
	// The default is 5.
	LogFileCount int

	// LogCompress determines if the rotated log files should be compressed
	// using gzip. The default is false.
	LogCompress bool

	// LogColorize enables output with colors
	LogColorize bool

	// TimeFormat sets the format for timestamp in logs. Valid formats are
	// "rfc3339", "iso8601", etc. The default is RFC3339.
	TimeFormat string

	// TimeZone sets the time zone to use for timestamps in logs.
	// The default is to use the local time zone.
	TimeZone string

	// LogToFileOnly disables logging to stdout.
	// If true, logs will only be written to the file and not also stdout.
	LogToFileOnly bool
}

Config defines the configuration options for the logger

type LogField

type LogField struct {
	Name  string
	Value any
}

func NewLogField

func NewLogField(name string, value any) LogField

NewLogField creates a new LogField struct with the given name and value. LogField is used to represent a key-value pair that can be attached to a log entry.

func NewLogFieldValue

func NewLogFieldValue(value any) LogField

NewLogFieldValue creates a new LogField with the given value.

Jump to

Keyboard shortcuts

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