Skip to content

Commit bcf5cb7

Browse files
committed
add some doc && benchmarks
1 parent 9f5aff2 commit bcf5cb7

File tree

5 files changed

+117
-20
lines changed

5 files changed

+117
-20
lines changed

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
language: go
22
go_import_path: github.com/nathanaelle/syslog5424/v2
33
go:
4-
- tip
5-
- 1.12
4+
- tip
5+
- 1.13
6+
- 1.12
67
branches:
78
except:
89
- /poc-.*/
910
- experimental
11+
env:
12+
- GO111MODULE=on

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 2-Clause License
22

3-
Copyright (c) 2015-2016, nathanaelle <[email protected]>
3+
Copyright (c) 2015-2020, nathanaelle <[email protected]>
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

ReadMe.markdown renamed to ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Syslog5424
22

3-
![License](http://img.shields.io/badge/license-Simplified_BSD-blue.svg?style=flat) [![Go Doc](http://img.shields.io/badge/godoc-syslog5424-blue.svg?style=flat)](http://godoc.org/github.com/nathanaelle/syslog5424) [![Build Status](https://travis-ci.org/nathanaelle/syslog5424.svg?branch=master)](https://travis-ci.org/nathanaelle/syslog5424) [![Coverage](http://gocover.io/_badge/github.com/nathanaelle/syslog5424)](http://gocover.io/github.com/nathanaelle/syslog5424)
3+
![License](http://img.shields.io/badge/license-Simplified_BSD-blue.svg?style=flat) [![Go Doc](http://img.shields.io/badge/godoc-syslog5424-blue.svg?style=flat)](http://godoc.org/github.com/nathanaelle/syslog5424) [![Build Status](https://travis-ci.org/nathanaelle/syslog5424.svg?branch=master)](https://travis-ci.org/nathanaelle/syslog5424) [![Go Report Card](https://goreportcard.com/badge/github.com/nathanaelle/syslog5424)](https://goreportcard.com/report/github.com/nathanaelle/syslog5424)
44

55
## Example
66

doc.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Package syslog5424 implements syslog RFC 5424 with a completly API compatibility with the standard log.Logger
3+
4+
5+
the simpliest way to use syslog5424 is :
6+
7+
8+
package main
9+
10+
import (
11+
"github.com/nathanaelle/syslog5424"
12+
)
13+
14+
func main() {
15+
// create a connection the standard error
16+
sl_conn, _, _ := syslog5424.Dial( "stdio", "stderr:" )
17+
18+
// create a syslog wrapper around the connection
19+
// the program is named "test-app" and you log to LogDAEMON facility at least at LogWARNING level
20+
syslog,_ := syslog5424.New( sl_conn, syslog5424.LogDAEMON|syslog5424.LogWARNING, "test-app" )
21+
22+
// create a channel for the level LogERR
23+
err_channel := syslog.Channel( syslog5424.LogERR )
24+
25+
// get a the *log.Logger for this channel with a prefix "ERR : "
26+
logger_err := err_channel.Logger( "ERR : " )
27+
28+
// log a message through the log.Logger
29+
logger_err.Print( "doing some stuff" )
30+
}
31+
32+
33+
34+
35+
36+
*/
37+
package syslog5424 // import "github.com/nathanaelle/syslog5424/v2"

message-immutable_test.go

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var parseTest = []string{
1717
`<165>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc 8710 - - %% It's time to make the do-nuts.`,
1818
`<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"] \xEF\xBB\xBFAn application event log entry...`,
1919
`<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"][examplePriority@32473 class="high"]`,
20-
`<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"][exampleEscape@32473 text="some[data\]here"]`,
20+
`<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"][exampleEscape@32473 text="some[data\] here"]`,
2121
}
2222

2323
func Test_MessageImmutable_Parse(t *testing.T) {
@@ -171,56 +171,113 @@ Actual performance are :
171171
172172
go test -cpu 1 -benchtime=10s -bench=MessageImmutable_Parse -benchmem
173173
goarch: amd64
174-
Benchmark_MessageImmutable_Parse_Minimal 100000000 199 ns/op 64 B/op 1 allocs/op
175-
Benchmark_MessageImmutable_Parse_MessageNoSD 100000000 228 ns/op 64 B/op 1 allocs/op
176-
Benchmark_MessageImmutable_Parse_KnownSDOnly 50000000 240 ns/op 64 B/op 1 allocs/op
177-
Benchmark_MessageImmutable_Parse_UnkownSDOnly 100000000 238 ns/op 64 B/op 1 allocs/op
178-
Benchmark_MessageImmutable_Parse_MessageAndSD 50000000 286 ns/op 64 B/op 1 allocs/op
174+
pkg: github.com/nathanaelle/syslog5424/v2
175+
Benchmark_MessageImmutable_Parse_Minimal 100000000 117 ns/op 64 B/op 1 allocs/op
176+
Benchmark_MessageImmutable_Parse_MessageNoSD 89648371 138 ns/op 64 B/op 1 allocs/op
177+
Benchmark_MessageImmutable_Parse_KnownSDOnly 87056971 140 ns/op 64 B/op 1 allocs/op
178+
Benchmark_MessageImmutable_Parse_UnkownSDOnly 88181227 140 ns/op 64 B/op 1 allocs/op
179+
Benchmark_MessageImmutable_Parse_MessageAndSD 75508340 163 ns/op 64 B/op 1 allocs/op
180+
Benchmark_MessageImmutable_Parse_Verylong 59195804 188 ns/op 64 B/op 1 allocs/op
181+
Benchmark_MessageImmutable_Parse_MaxLength 64618474 176 ns/op 64 B/op 1 allocs/op
182+
Benchmark_MessageImmutable_Parse_MessageAndSD_Then_Make_Mutable 5349686 2237 ns/op 736 B/op 24 allocs/op
179183
PASS
180184
181185
go test -cpu 4 -benchtime=10s -bench=MessageImmutable_Parse -benchmem
182186
goarch: amd64
183-
Benchmark_MessageImmutable_Parse_Minimal-4 100000000 182 ns/op 64 B/op 1 allocs/op
184-
Benchmark_MessageImmutable_Parse_MessageNoSD-4 100000000 207 ns/op 64 B/op 1 allocs/op
185-
Benchmark_MessageImmutable_Parse_KnownSDOnly-4 100000000 223 ns/op 64 B/op 1 allocs/op
186-
Benchmark_MessageImmutable_Parse_UnkownSDOnly-4 100000000 222 ns/op 64 B/op 1 allocs/op
187-
Benchmark_MessageImmutable_Parse_MessageAndSD-4 50000000 265 ns/op 64 B/op 1 allocs/op
187+
pkg: github.com/nathanaelle/syslog5424/v2
188+
Benchmark_MessageImmutable_Parse_Minimal-4 100000000 113 ns/op 64 B/op 1 allocs/op
189+
Benchmark_MessageImmutable_Parse_MessageNoSD-4 91566769 130 ns/op 64 B/op 1 allocs/op
190+
Benchmark_MessageImmutable_Parse_KnownSDOnly-4 90291741 130 ns/op 64 B/op 1 allocs/op
191+
Benchmark_MessageImmutable_Parse_UnkownSDOnly-4 92336280 129 ns/op 64 B/op 1 allocs/op
192+
Benchmark_MessageImmutable_Parse_MessageAndSD-4 76834656 154 ns/op 64 B/op 1 allocs/op
193+
Benchmark_MessageImmutable_Parse_Verylong-4 67873761 176 ns/op 64 B/op 1 allocs/op
194+
Benchmark_MessageImmutable_Parse_MaxLength-4 72529458 168 ns/op 64 B/op 1 allocs/op
195+
Benchmark_MessageImmutable_Parse_MessageAndSD_Then_Make_Mutable-4 5741421 2106 ns/op 736 B/op 24 allocs/op
188196
PASS
189197
190198
*/
191199

192200
func Benchmark_MessageImmutable_Parse_Minimal(b *testing.B) {
201+
var err error
202+
193203
data := []byte(`<0>1 1970-01-01T01:00:00+01:00 - - - - -`)
194204
for i := 0; i < b.N; i++ {
195-
Parse(data, nil, false)
205+
_, _, err = Parse(data, nil, false)
206+
}
207+
if err != nil {
208+
panic(err)
196209
}
197210
}
198211

199212
func Benchmark_MessageImmutable_Parse_MessageNoSD(b *testing.B) {
213+
var err error
214+
200215
data := []byte(`<165>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc 8710 - - %% It's time to make the do-nuts.`)
201216
for i := 0; i < b.N; i++ {
202-
Parse(data, nil, false)
217+
_, _, err = Parse(data, nil, false)
218+
}
219+
if err != nil {
220+
panic(err)
203221
}
204222
}
205223

206224
func Benchmark_MessageImmutable_Parse_KnownSDOnly(b *testing.B) {
225+
var err error
226+
207227
data := []byte(`<0>1 1970-01-01T01:00:00Z - - - - [timeQuality tzKnown="1" isSynced="1"]`)
208228
for i := 0; i < b.N; i++ {
209-
Parse(data, nil, false)
229+
_, _, err = Parse(data, nil, false)
230+
}
231+
if err != nil {
232+
panic(err)
210233
}
211234
}
212235

213236
func Benchmark_MessageImmutable_Parse_UnkownSDOnly(b *testing.B) {
237+
var err error
238+
214239
data := []byte(`<0>1 1970-01-01T01:00:00Z - - - - [timeQualitat tzKnown="1" isSynced="1"]`)
215240
for i := 0; i < b.N; i++ {
216-
Parse(data, nil, false)
241+
_, _, err = Parse(data, nil, false)
242+
}
243+
if err != nil {
244+
panic(err)
217245
}
218246
}
219247

220248
func Benchmark_MessageImmutable_Parse_MessageAndSD(b *testing.B) {
249+
var err error
250+
221251
data := []byte(`<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"][examplePriority@32473 class="high"] Some log message with structured data`)
222252
for i := 0; i < b.N; i++ {
223-
Parse(data, nil, false)
253+
_, _, err = Parse(data, nil, false)
254+
}
255+
if err != nil {
256+
panic(err)
257+
}
258+
}
259+
260+
func Benchmark_MessageImmutable_Parse_Verylong(b *testing.B) {
261+
var err error
262+
263+
data := []byte(`<190>1 2016-02-21T01:19:11+00:00 batch6sj - - - [meta sequenceId="21881798" x-group="37051387"][origin x-service="tracking"] metascutellar conversationalist nephralgic exogenetic graphy streng outtaken acouasm amateurism prenotice Lyonese bedull antigrammatical diosphenol gastriloquial bayoneteer sweetener naggy roughhouser dighter addend sulphacid uneffectless ferroprussiate reveal Mazdaist plaudite Australasian distributival wiseman rumness Seidel topazine shahdom sinsion mesmerically pinguedinous ophthalmotonometer scuppler wound eciliate expectedly carriwitchet dictatorialism bindweb pyelitic idic atule kokoon poultryproof rusticial seedlip nitrosate splenadenoma holobenthic uneternal Phocaean epigenic doubtlessly indirection torticollar robomb adoptedly outspeak wappenschawing talalgia Goop domitic savola unstrafed carded unmagnified mythologically orchester obliteration imperialine undisobeyed galvanoplastical cycloplegia quinquennia foremean umbonal marcgraviaceous happenstance theoretical necropoles wayworn Igbira pseudoangelic raising unfrounced lamasary centaurial Japanolatry microlepidoptera`)
264+
for i := 0; i < b.N; i++ {
265+
_, _, err = Parse(data, nil, false)
266+
}
267+
if err != nil {
268+
panic(err)
269+
}
270+
}
271+
272+
func Benchmark_MessageImmutable_Parse_MaxLength(b *testing.B) {
273+
var err error
274+
275+
data := []byte(`<191>1 2018-12-31T23:59:59.999999-23:59 abcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabc abcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdef abcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzab abcdefghilmnopqrstuvzabcdefghilm [an@id key1="val1" key2="val2"][another@id key1="val1"] Some message "GET"`)
276+
for i := 0; i < b.N; i++ {
277+
_, _, err = Parse(data, nil, false)
278+
}
279+
if err != nil {
280+
panic(err)
224281
}
225282
}
226283

0 commit comments

Comments
 (0)