diff --git a/flog.go b/flog.go index d6e1f24..c637c3c 100644 --- a/flog.go +++ b/flog.go @@ -122,6 +122,8 @@ func NewLog(format string, t time.Time) string { return NewApacheErrorLog(t) case "rfc3164": return NewRFC3164Log(t) + case "rfc5424": + return NewRFC5424Log(t) default: return "" } diff --git a/flog_test.go b/flog_test.go index 91e9b44..c71f2f4 100644 --- a/flog_test.go +++ b/flog_test.go @@ -21,12 +21,14 @@ func ExampleNewLog() { 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("unknown", created)) // Output: // 222.83.191.222 - Kozey7157 697 [2018-04-22T09:30:00Z] "DELETE /innovate/next-generation" 302 24570 // 174.144.199.149 - Mosciski7760 386 [2018-04-22T09:30:00Z] "GET /networks/revolutionary" 204 70360 "https://www.directeyeballs.org/streamline" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7) AppleWebKit/5312 (KHTML, like Gecko) Chrome/37.0.821.0 Mobile Safari/5312" // [2018-04-22T09:30:00Z] [tempore:warn] [pid 7401:tid 4039] [client: 184.155.77.136] Try to synthesize the SMS capacitor, maybe it will compress the online program! // <25>Apr 22 09:30:00 Fay5424 Monitored[5455]: Try to reboot the SMS bandwidth, maybe it will synthesize the mobile transmitter! + // <118>2 2018-04-22T09:30:00.000Z legacyb2b.com toolset 8605 ID854 - Try to synthesize the JBOD matrix, maybe it will calculate the 1080p application! // } diff --git a/log.go b/log.go index cda7d86..f898a14 100644 --- a/log.go +++ b/log.go @@ -16,6 +16,8 @@ const ( ApacheErrorLog = "[%s] [%s:%s] [pid %d:tid %d] [client: %s] %s" // RFC3164Log : {timestamp} {hostname} {application}[{pid}]: {message} RFC3164Log = "<%d>%s %s %s[%d]: %s" + // RFC5424Log : {version} {iso-timestamp} {hostname} {application} {pid} {message-id} {structured-data} {message} + RFC5424Log = "<%d>%d %s %s %s %d ID%d %s %s" ) // NewApacheCommonLog creates a log string with apache common log format @@ -76,3 +78,19 @@ func NewRFC3164Log(t time.Time) string { gofakeit.HackerPhrase(), ) } + +// NewRFC5424Log creates a log string with syslog (RFC5424) format +func NewRFC5424Log(t time.Time) string { + return fmt.Sprintf( + RFC5424Log, + gofakeit.Number(0, 191), + gofakeit.Number(1, 3), + t.Format(RFC5424), + gofakeit.DomainName(), + gofakeit.BuzzWord(), + gofakeit.Number(1, 10000), + gofakeit.Number(1, 1000), + "-", // TODO: structured data + gofakeit.HackerPhrase(), + ) +} diff --git a/log_test.go b/log_test.go index e557ddc..b2b7f95 100644 --- a/log_test.go +++ b/log_test.go @@ -53,3 +53,14 @@ func ExampleNewRFC3164Log() { fmt.Println(NewRFC3164Log(created)) // Output: <24>Apr 22 09:30:00 Moen8727 concept[3160]: If we back up the program, we can get to the SSL sensor through the redundant SAS program! } + +func ExampleNewRFC5424Log() { + 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 info-mediaries 9030 ID160 - If we back up the program, we can get to the SSL sensor through the redundant SAS program! +} diff --git a/option.go b/option.go index 4ec82d0..647e908 100644 --- a/option.go +++ b/option.go @@ -16,7 +16,7 @@ Usage: flog [options] Version: %s Options: - -f, --format string choose log format. ("apache_common"|"apache_combined"|"apache_error"|"rfc3164") (default "apache_common") + -f, --format string choose log format. ("apache_common"|"apache_combined"|"apache_error"|"rfc3164"|"rfc5424") (default "apache_common") -o, --output string output filename. Path-like is allowed. (default "generated.log") -t, --type string log output type. ("stdout"|"log"|"gz") (default "stdout") -n, --number integer number of lines to generate. @@ -31,7 +31,7 @@ Options: -l, --loop loop output forever until killed. ` -var validFormats = []string{"apache_common", "apache_combined", "apache_error", "rfc3164"} +var validFormats = []string{"apache_common", "apache_combined", "apache_error", "rfc3164", "rfc5424"} var validTypes = []string{"stdout", "log", "gz"} // Option defines log generator options diff --git a/time.go b/time.go index 7bbc9f8..f751dad 100644 --- a/time.go +++ b/time.go @@ -3,4 +3,5 @@ package main // Custom predefined layouts const ( RFC3164 = "Jan 02 15:04:05" + RFC5424 = "2006-01-02T15:04:05.000Z" )