Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: Rework options validation #14

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 78 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ For more information on testing see: https://golang.org/pkg/testing/

## API

### CreateLogger(Options, Key)
### NewLogger(Options, Key)
---

#### Options
Expand All @@ -115,38 +115,38 @@ For more information on testing see: https://golang.org/pkg/testing/
* Type: `string`
* Default: `''`
* Example Values: `YourCustomApp`
* Max Length: `32`
* Max Length: `80`

The default app passed along with every log sent through this instance.
Arbitrary app name for labeling each message.

##### Env

* _**Optional**_
* Type: `string`
* Default: `''`
* Example Values: `YourCustomEnvironment`
* Max Length: `32`
* Max Length: `80`

The default environment passed along with every log sent through this instance.
An environment label attached to each message.

##### FlushInterval

* _**Optional**_
* Type: `time.duration`
* Default: `5 * time.Second`
* Default: `250 * time.Millisecond`
* Example Values: `10 * time.Second`

The flush interval sets how often data is flushed and logs are shipped into LogDNA.
Time to wait before sending the buffer.

##### Hostname

* _**Optional**_
* Type: `string`
* Default: `''`
* Example Values: `YourCustomHostname`
* Max Length: `32`
* Max Length: `80`

The default hostname passed along with every log sent through this instance.
Hostname for each HTTP request.

##### IndexMeta

Expand All @@ -155,19 +155,15 @@ The default hostname passed along with every log sent through this instance.
* Default: `false`
* Example Values: `true`

We allow meta objects to be passed with each line. By default these meta objects will be stringified and will not be searchable, but will be displayed for informational purposes.

If this option is set to true then meta objects will be parsed and will be searchable up to three levels deep. Any fields deeper than three levels will be stringified and cannot be searched.

WARNING When this option is true, your metadata objects across all types of log messages MUST have consistent types or the metadata object may not be parsed properly!
Controls whether meta data for each message is searchable.

##### IngestURL

* _**Optional**_
* Type: `string`
* Default: `https://logs.logdna.com/logs/ingest`

A custom ingestion endpoint to stream log lines into.
URL of the logging server.

##### IPAddress

Expand All @@ -176,42 +172,51 @@ A custom ingestion endpoint to stream log lines into.
* Default: `''`
* Example Values: `10.0.0.1`

The default IP Address passed along with every log sent through this instance.
IPv4 or IPv6 address for each HTTP request.

##### Level

* _**Optional**_
* Type: `string`
* Default: `Info`
* Example Values: `Debug`, `Trace`, `Info`, `Warn`, `Error`, `Fatal`, `YourCustomLevel`
* Max Length: `32`
* Max Length: `80`

The default level passed along with every log sent through this instance.
Level to be used if not specified elsewhere.

##### MacAddress

* _**Optional**_
* Type: `string`
* Default: `''`
* Example Values: `C0:FF:EE:C0:FF:EE`
* Example Values: `c0:ff:ee:c0:ff:ee`

The default MAC Address passed along with every log sent through this instance.
MAC address for each HTTP request.

##### MaxBufferLen

* _**Optional**_
* Type: `int`
* Default: `5`
* Default: `50`
* Example Values: `10`

MaxBufferLen sets the number of logs that are buffered before data is flushed and shipped to LogDNA.
Maximum total line lengths before a flush is forced.

##### Meta

* _**Optional**_
* Type: `string`

A JSON string containing additional metadata about the log line that is passed.
Global metadata. Added to each message, unless overridden.

##### SendTimeout

* _**Optional**_
* Type: `time.Duration`
* Default: `30 * time.Second`
* Example Values: `10`

Time limit in seconds to wait for each HTTP request before timing out.

##### Tags

Expand All @@ -220,16 +225,16 @@ A JSON string containing additional metadata about the log line that is passed.
* Default: `5`
* Example Values: `logging,golang`

Tags to be added to each message.

List of tags used to dynamically group hosts.

#### Key
#### Timestamp

* _**Required**_
* Type: `string`
* Example Values: `123abc`
* _**Optional**_
* Type: `time.Time`
* Default Values: `time.Now()`
* Example Values: `time.Now()`

The [LogDNA Ingestion Key](https://app.logdna.com/manage/profile) associated with your account.
Epoch ms time to use if not provided elsewhere.
dm36 marked this conversation as resolved.
Show resolved Hide resolved

---

Expand All @@ -240,7 +245,7 @@ The [LogDNA Ingestion Key](https://app.logdna.com/manage/profile) associated wit
* Type: `string`
* Default: `''`

The line/message to be sent to the LogDNA system.
Text of the log entry.

---

Expand All @@ -252,7 +257,7 @@ The line/message to be sent to the LogDNA system.
* Type: `string`
* Default: `''`

The line/message to be sent to the LogDNA system.
Text of the log entry.

#### Options

Expand All @@ -262,38 +267,38 @@ The line/message to be sent to the LogDNA system.
* Type: `string`
* Default: `''`
* Example Values: `YourCustomApp`
* Max Length: `32`
* Max Length: `80`

The default app passed along with every log sent through this instance.
App name to use for the current message.

##### Env

* _**Optional**_
* Type: `string`
* Default: `''`
* Example Values: `YourCustomEnvironment`
* Max Length: `32`
* Max Length: `80`

The default environment passed along with every log sent through this instance.
Environment name to use for the current message.

##### FlushInterval

* _**Optional**_
* Type: `time.duration`
* Default: `5`
* Example Values: `YourCustomEnvironment`
* Default: `250 * time.Millisecond`
* Example Values: `10 * time.Second`

The flush interval sets how often data is flushed and logs shipped into LogDNA.
Time to wait before sending the buffer.

##### Hostname

* _**Optional**_
* Type: `string`
* Default: `''`
* Example Values: `YourCustomHostname`
* Max Length: `32`
* Max Length: `80`

The default hostname passed along with every log sent through this instance.
Hostname to use for the current message.

##### IndexMeta

Expand All @@ -302,19 +307,15 @@ The default hostname passed along with every log sent through this instance.
* Default: `false`
* Example Values: `true`

We allow meta objects to be passed with each line. By default these meta objects will be stringified and will not be searchable, but will be displayed for informational purposes.

If this option is turned to true then meta objects will be parsed and will be searchable up to three levels deep. Any fields deeper than three levels will be stringified and cannot be searched.

WARNING When this option is true, your metadata objects across all types of log messages MUST have consistent types or the metadata object may not be parsed properly!
Allows for the meta to be searchable in LogDNA.

##### IngestURL

* _**Optional**_
* Type: `string`
* Default: `https://logs.logdna.com/logs/ingest`

A custom ingestion endpoint to stream log lines into.
URL of the logging server.

##### IPAddress

Expand All @@ -323,42 +324,51 @@ A custom ingestion endpoint to stream log lines into.
* Default: `''`
* Example Values: `10.0.0.1`

The default IP Address passed along with every log sent through this instance.
IPv4 or IPv6 address for the current message.

##### Level

* _**Optional**_
* Type: `string`
* Default: `Info`
* Example Values: `Debug`, `Trace`, `Info`, `Warn`, `Error`, `Fatal`, `YourCustomLevel`
* Max Length: `32`
* Max Length: `80`

The default level passed along with every log sent through this instance.
Desired level for the current message.

##### MacAddress

* _**Optional**_
* Type: `string`
* Default: `''`
* Example Values: `C0:FF:EE:C0:FF:EE`
* Example Values: `c0:ff:ee:c0:ff:ee`

The default MAC Address passed along with every log sent through this instance.
MAC address for the current message.

##### MaxBufferLen

* _**Optional**_
* Type: `int`
* Default: `5`
* Default: `50`
* Example Values: `10`

MaxBufferLen sets the number of logs that are buffered before data is flushed and shipped to LogDNA.
Maximum total line lengths before a flush is forced.

##### Meta

* _**Optional**_
* Type: `Meta`
* Type: `string`

Per-message meta data.

A meta object for additional metadata about the log line that is passed.
##### SendTimeout

* _**Optional**_
* Type: `time.Duration`
* Default: `30 * time.Second`
* Example Values: `10`

Time limit in seconds to wait before timing out.

##### Tags

Expand All @@ -367,8 +377,16 @@ A meta object for additional metadata about the log line that is passed.
* Default: `5`
* Example Values: `logging,golang`

Tags to be added for the current message.

#### Timestamp

* _**Optional**_
* Type: `time.Time`
* Default Values: `time.Now()`
* Example Values: `time.Now()`

List of tags used to dynamically group hosts.
Epoch ms time to use for the current message.

---

Expand All @@ -380,17 +398,17 @@ List of tags used to dynamically group hosts.
* Type: `string`
* Default: `''`

The line which will be sent to the LogDNA system.
Text of the log entry.

#### Level

* _**Required**_
* Type: `string`
* Default: ``
* Example Values: `Debug`, `Trace`, `Info`, `Warn`, `Error`, `Fatal`, `YourCustomLevel`
* Max Length: `32`
* Max Length: `80`

The default level passed along with every log sent through this instance.
Desired level for the current message.

---

Expand Down
7 changes: 4 additions & 3 deletions logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestLogger_NewLogger(t *testing.T) {

t.Run("Invalid options", func(t *testing.T) {
o := Options{
Level: strings.Repeat("a", 33),
Level: strings.Repeat("a", 83),
}

_, err := NewLogger(o, "abc123")
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestLogger_Log(t *testing.T) {
assert.Equal(t, "abc123", body["apikey"])
assert.Equal(t, "foo", body["hostname"])
assert.Equal(t, "127.0.0.1", body["ip"])
assert.Equal(t, "C0:FF:EE:C0:FF:EE", body["mac"])
assert.Equal(t, "c0:ff:ee:c0:ff:ee", body["mac"])
assert.NotEmpty(t, body["lines"])

ls := body["lines"].([]interface{})
Expand Down Expand Up @@ -126,6 +126,7 @@ func TestLogger_LogWithOptions(t *testing.T) {
assert.Equal(t, "production", line["env"])
assert.Equal(t, "error", line["level"])
assert.Equal(t, now.UnixNano()/int64(time.Millisecond), int64(line["timestamp"].(float64)))
dm36 marked this conversation as resolved.
Show resolved Hide resolved

})

t.Run("Invalid options", func(t *testing.T) {
Expand All @@ -139,7 +140,7 @@ func TestLogger_LogWithOptions(t *testing.T) {
assert.Equal(t, nil, err)

err = l.LogWithOptions("testing", Options{
App: strings.Repeat("a", 33),
App: strings.Repeat("a", 83),
})

assert.Error(t, err)
Expand Down
Loading