queries

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFilters

func AddFilters(configs ...logger.QueryOption) logger.QueryOption

AddFilters returns a QueryOption that appends the given filters to the base query This is useful to add multiple filters to the query Example:

queryOpt := queries.AddFilters(queries.LevelEqual(logger.Info), queries.CallerFileLike("main"))

Note: this metod is useful if you want to use custom QueryOprions to filter the logs If you use the QueryOptions provided by this package, you can avoid to use this method beacuse every QueryOption already has the logic to add the filter to the query without conflicting with other QueryOptions.

func AddLimit

func AddLimit(limitAndOffset ...int) logger.QueryOption

AddLimit returns a QueryOption that appends the given limit and offset to the base query This is useful to add the limit and offset to the query

  • If only one argument is provided, it will be used as the limit
  • If two arguments are provided, the first will be used as the limit and the second as the offset
  • If no arguments are provided, the method does nothing

Example:

queryOpt := queries.AddLimit(10)
queryOpt := queries.AddLimit(10, 5)

In the first example, the query will have a limit of 10 logs and no offset In the second example, the query will have a limit of 10 logs and an offset of 5

func AddSorts

func AddSorts(configs ...logger.QueryOption) logger.QueryOption

AddSorts returns a QueryOption that appends the given sorts to the base query This is useful to add multiple sorts to the query Example:

queryOpt := queries.AddSorts(logger.SortLevel("DESC"), queries.SortTimestamp("ASC"))

Note: this metod is useful if you want to use custom QueryOprions to sort the logs If you use the QueryOptions provided by this package, you can avoid to use this method beacuse every QueryOption already has the logic to add the sort to the query without conflicting with other QueryOptions.

func CallerFileLike

func CallerFileLike(file string) logger.QueryOption

CallerFileLike returns a QueryOption that filters the logs by the given file Example:

queryOpt := queries.CallerFileLike("main.go")

In this example, the query will return all the logs with the caller file set to main.go or any other file with the string "main.go" in its name

func CallerFileNotLike

func CallerFileNotLike(file string) logger.QueryOption

CallerFileNotLike returns a QueryOption that filters the logs by the files different from the given file Example:

queryOpt := queries.CallerFileNotLike("main.go")

In this example, the query will return all the logs with the caller file different from main.go or any other file without the string "main.go" in its name

func CallerFunctionLike

func CallerFunctionLike(function string) logger.QueryOption

CallerFunctionLike returns a QueryOption that filters the logs by the given function Example:

queryOpt := queries.CallerFunctionLike("main.main")

In this example, the query will return all the logs with the caller function set to main.main or any other function with the string "main.main" in its name

func CallerFunctionNotLike

func CallerFunctionNotLike(function string) logger.QueryOption

CallerFunctionNotLike returns a QueryOption that filters the logs by the functions different from the given function Example:

queryOpt := queries.CallerFunctionNotLike("main.main")

In this example, the query will return all the logs with the caller function different from main.main or any other function without the string "main.main" in its name

func CallerLineBetween

func CallerLineBetween(start, end int) logger.QueryOption

CallerLineBetween returns a QueryOption that filters the logs by the lines between the given start and end lines Example:

queryOpt := queries.CallerLineBetween(10, 20)

In this example, the query will return all the logs with the caller line between 10 and 20

func CallerLineEqual

func CallerLineEqual(line int) logger.QueryOption

CallerLineEqual returns a QueryOption that filters the logs by the given line Example:

queryOpt := queries.CallerLineEqual(10)

In this example, the query will return all the logs with the caller line set to 10

func CallerLineGreaterThan

func CallerLineGreaterThan(line int) logger.QueryOption

CallerLineGreaterThan returns a QueryOption that filters the logs by the lines greater than the given line Example:

queryOpt := queries.CallerLineGreaterThan(10)

In this example, the query will return all the logs with the caller line greater than 10

func CallerLineLessThan

func CallerLineLessThan(line int) logger.QueryOption

CallerLineLessThan returns a QueryOption that filters the logs by the lines less than the given line Example:

queryOpt := queries.CallerLineLessThan(10)

In this example, the query will return all the logs with the caller line less than 10

func CallerLineNotEqual

func CallerLineNotEqual(line int) logger.QueryOption

CallerLineNotEqual returns a QueryOption that filters the logs by the lines different from the given line Example:

queryOpt := queries.CallerLineNotEqual(10)

In this example, the query will return all the logs with the caller line different from 10

func CustomQuery

func CustomQuery(query string) logger.QueryOption

CustomQuery returns a QueryOption that appends the given query to the base query This is useful for custom queries that are not covered by the other QueryOptions Example:

queryOpt := queries.CustomQuery("WHERE level = 1 OR level = 3 ORDER BY time DESC")

In this example te custom query is very simple, but it can be as complex as needed, as long as it is a valid SQL query. Note the base query is not needed, as it is already defined in the package. The custom query is appended to the base query. The resulting query will be:

SELECT id, level, caller_file, caller_line, caller_function, message, time FROM logs WHERE level = 1 OR level = 3 ORDER BY time DESC

The main approach for this package is to use the other QueryOptions, as they are more specific and easier to use.

func DateBetween

func DateBetween(start, end time.Time) logger.QueryOption

DateBetween returns a QueryOption that filters the logs by the dates between the given start and end dates Example:

queryOpt := queries.DateBetween(time.Now().Add(-24*time.Hour), time.Now())

In this example, the query will return all the logs with the date between 24 hours ago and the current date it consider only the date, not the time

func DateEqual

func DateEqual(date time.Time) logger.QueryOption

DateEqual returns a QueryOption that filters the logs by the given date Example:

queryOpt := queries.DateEqual(time.Now())

In this example, the query will return all the logs with the date set to the current date it consider only the date, not the time

func DateGreaterThan

func DateGreaterThan(date time.Time) logger.QueryOption

DateGreaterThan returns a QueryOption that filters the logs by the dates greater than the given date Example:

queryOpt := queries.DateGreaterThan(time.Now())

In this example, the query will return all the logs with the date greater than the current date it consider only the date, not the time

func DateLessThan

func DateLessThan(date time.Time) logger.QueryOption

DateLessThan returns a QueryOption that filters the logs by the dates less than the given date Example:

queryOpt := queries.DateLessThan(time.Now())

In this example, the query will return all the logs with the date less than the current date it consider only the date, not the time

func DateNotEqual

func DateNotEqual(date time.Time) logger.QueryOption

DateNotEqual returns a QueryOption that filters the logs by the dates different from the given date Example:

queryOpt := queries.DateNotEqual(time.Now())

In this example, the query will return all the logs with the date different from the current date it consider only the date, not the time

func HasTags

func HasTags(tag string, tags ...string) logger.QueryOption

HasTags returns a QueryOption that filters the logs by the given tags the logs must have at least one of the given tags Example:

queryOpt := queries.HasTags("tag1", "tag2")

In this example, the query will return all the logs with the tags set to tag1 or tag2 or any other tag with the string "tag1" or "tag2" in its name The query will return the logs with at least one of the given tags

func LevelBetween

func LevelBetween(start, end logger.LogLevel) logger.QueryOption

LevelBetween returns a QueryOption that filters the logs by the levels between the given start and end levels Example:

queryOpt := queries.LevelBetween(logger.Info, logger.Warning) // info, warning

In this example, the query will return all the logs with the level between Info and Warning

func LevelEqual

func LevelEqual(level logger.LogLevel) logger.QueryOption

LevelEqual returns a QueryOption that filters the logs by the given level Example:

queryOpt := queries.LevelEqual(logger.Info)

In this example, the query will return all the logs with the level set to Info

func LevelGreaterThan

func LevelGreaterThan(level logger.LogLevel) logger.QueryOption

LevelGreaterThan returns a QueryOption that filters the logs by the levels greater than the given level Example:

queryOpt := queries.LevelGreaterThan(logger.Info) // warning, error, fatal

In this example, the query will return all the logs with the level greater than Info

func LevelLessThan

func LevelLessThan(level logger.LogLevel) logger.QueryOption

LevelLessThan returns a QueryOption that filters the logs by the levels less than the given level Example:

queryOpt := queries.LevelLessThan(logger.Info) // debug

In this example, the query will return all the logs with the level less than Info

func LevelNotEqual

func LevelNotEqual(level logger.LogLevel) logger.QueryOption

LevelNotEqual returns a QueryOption that filters the logs by the levels different from the given level Example:

queryOpt := queries.LevelNotEqual(logger.Info)

In this example, the query will return all the logs with the level different from Info

func MessageLike

func MessageLike(message string) logger.QueryOption

MessageLike returns a QueryOption that filters the logs by the given message Example:

queryOpt := queries.MessageLike("error")

In this example, the query will return all the logs with the message set to error or any other message with the string "error" in its content

func MessageNotLike

func MessageNotLike(message string) logger.QueryOption

MessageNotLike returns a QueryOption that filters the logs by the messages different from the given message Example:

queryOpt := queries.MessageNotLike("error")

In this example, the query will return all the logs with the message different from error or any other message without the string "error" in its content

func SortCallerFile

func SortCallerFile(order string) logger.QueryOption

SortTags returns a QueryOption that sorts the logs by the tags Example:

queryOpt := queries.SortTags("ASC")

In this example, the query will return the logs sorted by the tags in ascending order it accept only "ASC"/"asc" or "DESC"/"desc" as order. If the order is not valid, it will default to "ASC"

func SortCallerFunction

func SortCallerFunction(order string) logger.QueryOption

SortCallerFunction returns a QueryOption that sorts the logs by the function of the caller Example:

queryOpt := queries.SortCallerFunction("ASC")

In this example, the query will return the logs sorted by the function of the caller in ascending order it accept only "ASC"/"asc" or "DESC"/"desc" as order. If the order is not valid, it will default to "ASC"

func SortCallerLine

func SortCallerLine(order string) logger.QueryOption

SortCallerLine returns a QueryOption that sorts the logs by the line of the caller Example:

queryOpt := queries.SortCallerLine("ASC")

In this example, the query will return the logs sorted by the line of the caller in ascending order it accept only "ASC"/"asc" or "DESC"/"desc" as order. If the order is not valid, it will default to "ASC"

func SortLevel

func SortLevel(order string) logger.QueryOption

SortLevel returns a QueryOption that sorts the logs by the level Example:

queryOpt := queries.SortLevel("DESC")

In this example, the query will return the logs sorted by the level in descending order it accept only "ASC"/"asc" or "DESC"/"desc" as order. If the order is not valid, it will default to "ASC"

func SortMessage

func SortMessage(order string) logger.QueryOption

SortMessage returns a QueryOption that sorts the logs by the message Example:

queryOpt := queries.SortMessage("ASC")

In this example, the query will return the logs sorted by the message in ascending order it accept only "ASC"/"asc" or "DESC"/"desc" as order. If the order is not valid, it will default to "ASC"

func SortTimestamp

func SortTimestamp(order string) logger.QueryOption

SortTimestamp returns a QueryOption that sorts the logs by the timestamp Example:

queryOpt := queries.SortTimestamp("ASC")

In this example, the query will return the logs sorted by the timestamp in ascending order it accept only "ASC"/"asc" or "DESC"/"desc" as order. If the order is not valid, it will default to "ASC"

func TimestampBetween

func TimestampBetween(start, end time.Time) logger.QueryOption

TimestampBetween returns a QueryOption that filters the logs by the timestamps between the given start and end timestamps Example:

queryOpt := queries.TimestampBetween(time.Now().Add(-time.Hour), time.Now())

In this example, the query will return all the logs with the timestamp between one hour ago and the current time it consider both date and time

func TimestampEqual

func TimestampEqual(timestamp time.Time) logger.QueryOption

TimestampEqual returns a QueryOption that filters the logs by the given timestamp Example:

queryOpt := queries.TimestampEqual(time.Now())

In this example, the query will return all the logs with the timestamp set to the current time it consider both date and time

func TimestampGreaterThan

func TimestampGreaterThan(timestamp time.Time) logger.QueryOption

TimestampGreaterThan returns a QueryOption that filters the logs by the timestamps greater than the given timestamp Example:

queryOpt := queries.TimestampGreaterThan(time.Now())

In this example, the query will return all the logs with the timestamp greater than the current time it consider both date and time

func TimestampLessThan

func TimestampLessThan(timestamp time.Time) logger.QueryOption

TimestampLessThan returns a QueryOption that filters the logs by the timestamps less than the given timestamp Example:

queryOpt := queries.TimestampLessThan(time.Now())

In this example, the query will return all the logs with the timestamp less than the current time it consider both date and time

func TimestampNotEqual

func TimestampNotEqual(timestamp time.Time) logger.QueryOption

TimestampNotEqual returns a QueryOption that filters the logs by the timestamps different from the given timestamp Example:

queryOpt := queries.TimestampNotEqual(time.Now())

In this example, the query will return all the logs with the timestamp different from the current time it consider both date and time

Types

This section is empty.

Jump to

Keyboard shortcuts

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