flog

package
v0.0.0-...-d242a11 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// ApacheCommonLog : {host} {user-identifier} {auth-user-id} [{datetime}] "{method} {request} {protocol}" {response-code} {bytes}
	ApacheCommonLog = "%s - %s [%s] \"%s %s %s\" %d %d"
	// ApacheCombinedLog : {host} {user-identifier} {auth-user-id} [{datetime}] "{method} {request} {protocol}" {response-code} {bytes} "{referrer}" "{agent}"
	ApacheCombinedLog = "%s - %s [%s] \"%s %s %s\" %d %d \"%s\" \"%s\""
	// ApacheErrorLog : [{timestamp}] [{module}:{severity}] [pid {pid}:tid {thread-id}] [client %{client}:{port}] %{message}
	ApacheErrorLog = "[%s] [%s:%s] [pid %d:tid %d] [client %s:%d] %s"
	// RFC3164Log : <priority>{timestamp} {hostname} {application}[{pid}]: {message}
	RFC3164Log = "<%d>%s %s %s[%d]: %s"
	// RFC5424Log : <priority>{version} {iso-timestamp} {hostname} {application} {pid} {message-id} {structured-data} {message}
	RFC5424Log = "<%d>%d %s %s %s %d ID%d %s %s"
	// CommonLogFormat : {host} {user-identifier} {auth-user-id} [{datetime}] "{method} {request} {protocol}" {response-code} {bytes}
	CommonLogFormat = "%s - %s [%s] \"%s %s %s\" %d %d"
	// JSONLogFormat : {"host": "{host}", "user-identifier": "{user-identifier}", "datetime": "{datetime}", "method": "{method}", "request": "{request}", "protocol": "{protocol}", "status", {status}, "bytes": {bytes}, "referer": "{referer}"}
	JSONLogFormat = `` /* 146-byte string literal not displayed */
)
View Source
const (
	Apache      = "02/Jan/2006:15:04:05 -0700"
	ApacheError = "Mon Jan 02 15:04:05 2006"
	RFC3164     = "Jan 02 15:04:05"
	RFC5424     = "2006-01-02T15:04:05.000Z"
	CommonLog   = "02/Jan/2006:15:04:05 -0700"
)

Custom predefined layouts

Variables

This section is empty.

Functions

func Generate

func Generate(option *Option) error

Generate generates the logs with given options

func NewApacheCombinedLog

func NewApacheCombinedLog(t time.Time) string

NewApacheCombinedLog creates a log string with apache combined log format

Example
rand.Seed(11)

monkey.Patch(time.Now, func() time.Time { return stopped })
defer monkey.Unpatch(time.Now)

created := time.Now()
fmt.Println(NewApacheCombinedLog(created))
Output:

222.83.191.222 - - [22/Apr/2018:09:30:00 +0000] "DELETE /innovate/next-generation HTTP/1.1" 406 97484 "https://www.humanscalable.io/synergize/morph/sticky" "Mozilla/5.0 (Windows NT 5.01) AppleWebKit/5320 (KHTML, like Gecko) Chrome/40.0.875.0 Mobile Safari/5320"

func NewApacheCommonLog

func NewApacheCommonLog(t time.Time) string

NewApacheCommonLog creates a log string with apache common log format

Example
rand.Seed(11)

monkey.Patch(time.Now, func() time.Time { return stopped })
defer monkey.Unpatch(time.Now)

created := time.Now()
fmt.Println(NewApacheCommonLog(created))
Output:

222.83.191.222 - - [22/Apr/2018:09:30:00 +0000] "DELETE /innovate/next-generation HTTP/1.1" 406 7610

func NewApacheErrorLog

func NewApacheErrorLog(t time.Time) string

NewApacheErrorLog creates a log string with apache error log format

Example
rand.Seed(11)

monkey.Patch(time.Now, func() time.Time { return stopped })
defer monkey.Unpatch(time.Now)

created := time.Now()
fmt.Println(NewApacheErrorLog(created))
Output:

[Sun Apr 22 09:30:00 2018] [quia:crit] [pid 4214:tid 6037] [client 90.151.9.107:14075] Copying the protocol won't do anything, we need to copy the redundant SAS program!

func NewCommonLogFormat

func NewCommonLogFormat(t time.Time) string

NewCommonLogFormat creates a log string with common log format

Example
rand.Seed(11)

monkey.Patch(time.Now, func() time.Time { return stopped })
defer monkey.Unpatch(time.Now)

created := time.Now()
fmt.Println(NewCommonLogFormat(created))
Output:

222.83.191.222 - - [22/Apr/2018:09:30:00 +0000] "DELETE /innovate/next-generation HTTP/1.1" 406 7610

func NewJSONLogFormat

func NewJSONLogFormat(t time.Time) string

NewJSONLogFormat creates a log string with json log format

Example
rand.Seed(11)

monkey.Patch(time.Now, func() time.Time { return stopped })
defer monkey.Unpatch(time.Now)

created := time.Now()
fmt.Println(NewJSONLogFormat(created))
Output:

{"host":"222.83.191.222", "user-identifier":"-", "datetime":"22/Apr/2018:09:30:00 +0000", "method": "DELETE", "request": "/innovate/next-generation", "protocol":"HTTP/1.1", "status":406, "bytes":7610, "referer": "https://www.humanscalable.io/synergize/morph/sticky"}

func NewLog

func NewLog(format string, t time.Time) string

NewLog creates a log for given format

Example
rand.Seed(11)

monkey.Patch(time.Now, func() time.Time { return stopped })
defer monkey.Unpatch(time.Now)

created := time.Now()
fmt.Println(NewLog("apache_common", created))
fmt.Println(NewLog("apache_combined", created))
fmt.Println(NewLog("apache_error", created))
fmt.Println(NewLog("rfc3164", created))
fmt.Println(NewLog("rfc5424", created))
fmt.Println(NewLog("common_log", created))
fmt.Println(NewLog("unknown", created))
fmt.Println(NewLog("json", created))
Output:

222.83.191.222 - - [22/Apr/2018:09:30:00 +0000] "DELETE /innovate/next-generation HTTP/1.1" 406 7610
144.199.149.125 - waelchi7603 [22/Apr/2018:09:30:00 +0000] "PUT /revolutionary HTTP/1.1" 301 8089 "https://www.futureaggregate.io/users" "Mozilla/5.0 (Macintosh; PPC Mac OS X 10_6_5 rv:4.0; en-US) AppleWebKit/536.38.2 (KHTML, like Gecko) Version/6.0 Safari/536.38.2"
[Sun Apr 22 09:30:00 2018] [eaque:error] [pid 3748:tid 2783] [client 54.26.161.221:31944] Backing up the program won't do anything, we need to compress the optical PCI bandwidth!
<94>Apr 22 09:30:00 ortiz5384 vel[1775]: If we copy the firewall, we can get to the PCI firewall through the redundant SQL port!
<23>3 2018-04-22T09:30:00.000Z humaniterate.io iusto 544 ID177 - Use the optical RAM hard drive, then you can program the auxiliary feed!
195.44.200.155 - kihn6187 [22/Apr/2018:09:30:00 +0000] "GET /revolutionary/e-markets/holistic/syndicate HTTP/2.0" 404 14503

{"host":"13.108.182.26", "user-identifier":"bailey7205", "datetime":"22/Apr/2018:09:30:00 +0000", "method": "GET", "request": "/out-of-the-box/architectures/embrace", "protocol":"HTTP/1.0", "status":200, "bytes":5921, "referer": "http://www.dynamicexperiences.io/robust"}

func NewRFC3164Log

func NewRFC3164Log(t time.Time) string

NewRFC3164Log creates a log string with syslog (RFC3164) format

Example
rand.Seed(11)

monkey.Patch(time.Now, func() time.Time { return stopped })
defer monkey.Unpatch(time.Now)

created := time.Now()
fmt.Println(NewRFC3164Log(created))
Output:

<24>Apr 22 09:30:00 moen8727 quo[3160]: If we back up the program, we can get to the SSL sensor through the redundant SAS program!

func NewRFC5424Log

func NewRFC5424Log(t time.Time) string

NewRFC5424Log creates a log string with syslog (RFC5424) format

Example
rand.Seed(11)

monkey.Patch(time.Now, func() time.Time { return stopped })
defer monkey.Unpatch(time.Now)

created := time.Now()
fmt.Println(NewRFC5424Log(created))
Output:

<24>3 2018-04-22T09:30:00.000Z futurefunctionalities.biz nisi 9030 ID160 - If we back up the program, we can get to the SSL sensor through the redundant SAS program!

func NewSplitFileName

func NewSplitFileName(path string, count int) string

NewSplitFileName creates a new file path with split count

func NewWriter

func NewWriter(logType string, logFileName string) (io.WriteCloser, error)

NewWriter returns a closeable writer corresponding to given log type

func ParseBytes

func ParseBytes(bytes int) (int, error)

ParseBytes validates the given bytes

func ParseDelay

func ParseDelay(delayString string) (time.Duration, error)

ParseDelay validates the given sleep

func ParseFormat

func ParseFormat(format string) (string, error)

ParseFormat validates the given format

func ParseNumber

func ParseNumber(lines int) (int, error)

ParseNumber validates the given number

func ParseSleep

func ParseSleep(sleepString string) (time.Duration, error)

ParseSleep validates the given sleep

func ParseSplitBy

func ParseSplitBy(splitBy int) (int, error)

ParseSplitBy validates the given split-by

func ParseType

func ParseType(logType string) (string, error)

ParseType validates the given type

func RandAuthUserID

func RandAuthUserID() string

RandAuthUserID generates a random auth user id

func RandHTTPVersion

func RandHTTPVersion() string

RandHTTPVersion returns a random http version

func RandResourceURI

func RandResourceURI() string

RandResourceURI generates a random resource URI

Example
rand.Seed(11)
fmt.Print(RandResourceURI())
Output:

/target

func Run

func Run(option *Option) error

Run checks overwrite flag and generates logs with given options

Types

type Option

type Option struct {
	Format    string
	Output    string
	Type      string
	Number    int
	Bytes     int
	Sleep     time.Duration
	Delay     time.Duration
	SplitBy   int
	Overwrite bool
	Forever   bool
}

Option defines log generator options

func ParseOptions

func ParseOptions() *Option

ParseOptions parses given parameters from command line

Jump to

Keyboard shortcuts

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