Skip to content

Commit

Permalink
Adds examples, updates README and removes logger subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
dm36 committed Sep 2, 2020
1 parent 97a882a commit 6e2d6d6
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ jobs:
- run:
name: "Lint"
command: |
golint -set_exit_status **/*.go
golint -set_exit_status *.go
- run:
name: "Run tests"
command: |
mkdir -p /tmp/artifacts
go test -v -coverprofile=/tmp/artifacts/profile.out -covermode=count ./logger
go test -v -coverprofile=/tmp/artifacts/profile.out -covermode=count
go tool cover -html=/tmp/artifacts/profile.out -o /tmp/artifacts/coverage.html
goveralls -coverprofile=/tmp/artifacts/profile.out -service=circleci -repotoken $COVERALLS_REPO_TOKEN
- store_artifacts:
Expand All @@ -39,7 +39,7 @@ jobs:
- checkout
- run:
name: ZIP the Codebase
command: zip logdna-go.zip -r logger/logdna.go go.mod
command: zip logdna-go.zip -r logger.go logger_test.go options.go options_test.go go.mod
- persist_to_workspace:
root: .
paths:
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<p align="center">Go library for logging to <a href="https://app.logdna.com">LogDNA</a></p>
</p>

[![CircleCI](https://circleci.com/gh/logdna/logdna-go/tree/master.svg?style=svg)](https://circleci.com/gh/logdna/logdna-go/tree/master)
[![Coverage Status](https://coveralls.io/repos/github/logdna/logdna-go/badge.svg?branch=master)](https://coveralls.io/github/logdna/logdna-go?branch=master)
[![GoDoc](https://godoc.org/github.com/logdna/logdna-go?status.svg)](https://godoc.org/github.com/logdna/logdna-go/logger)
[![CircleCI](https://circleci.com/gh/logdna/logger-go/tree/master.svg?style=svg)](https://circleci.com/gh/logdna/logdna-go/tree/master)
[![Coverage Status](https://coveralls.io/repos/github/logdna/logger-go/badge.svg?branch=master)](https://coveralls.io/github/logdna/logdna-go?branch=master)
[![GoDoc](https://godoc.org/github.com/logdna/logger-go?status.svg)](https://godoc.org/github.com/logdna/logdna-go/logger)

🚧 Work in progress 🚧

Expand All @@ -22,13 +22,13 @@
## Install

```
go get github.com/logdna/logdna-go
go get github.com/logdna/logger-go
```

## Setup
```golang
import (
"github.com/logdna/logdna-go/logger"
"github.com/logdna/logger-go"
)

func main() {
Expand Down Expand Up @@ -92,12 +92,12 @@ You will see these logs in your LogDNA dashboard! Make sure to run .Close() when
Run all tests in the test suite:

```
go test ./logger
go test
```

Run a specific test:
```
go test ./logger -run ^TestLogger_LogWithOptions$
go test -run ^TestLogger_LogWithOptions$
```

For more information on testing see: https://golang.org/pkg/testing/
Expand Down
50 changes: 50 additions & 0 deletions examples/example_readme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"github.com/logdna/logger-go"
"fmt"
)

func main() {
key := "YOUR INGESTION KEY"

// Configure your options with your desired level, hostname, app, ip address, mac address and environment.
// Hostname is the only required field in your options- the rest are optional.
options := Options{}
options.Level = "fatal"
options.Hostname = "gotest"
options.App = "myapp"
options.IPAddress = "10.0.1.101"
options.MacAddress = "C0:FF:EE:C0:FF:EE"
options.Env = "production"
options.Tags = "logging,golang"

myLogger, err := CreateLogger(options, key)
fmt.Println(err)
myLogger.Log("Message 1")
myLogger.Close()

// Can also use Go's short-hand syntax for initializing structs to define all your options in just a single line:
options = Options{Level: "error", Hostname: "gotest", App: "myapp", IPAddress: "10.0.1.101", MacAddress: "C0:FF:EE:C0:FF:EE"}
myLogger2, err := CreateLogger(options, key)
myLogger2.Log("Message 2")

// Configure options with specific logs
newOptions := Options{Level: "warning", Hostname: "gotest", App: "myotherapp", IPAddress: "10.0.1.101", MacAddress: "C0:FF:EE:C0:FF:EE"}
errWithOpts := myLogger2.LogWithOptions("Message 3", newOptions)
fmt.Println(errWithOpts)

// We support the following 6 levels
myLogger2.Info("Message 1")
myLogger2.Warn("Message 2")
myLogger2.Debug("Message 3")
myLogger2.Error("Message 4")
myLogger2.Fatal("Message 5")
myLogger2.Critical("Message 6")

// To add metadata to every log-line created by the logger instance:
options.Meta = `{"key": "value", "key2": "value2"}`
myLogger3, err := CreateLogger(options, key)
myLogger3.Log("Message 7")
myLogger3.Close()
}
2 changes: 1 addition & 1 deletion logger/logger.go → logger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package logger
package main

import (
"bytes"
Expand Down
3 changes: 1 addition & 2 deletions logger/logger_test.go → logger_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package logger

package main
import (
"encoding/json"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion logger/options.go → options.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package logger
package main

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion logger/options_test.go → options_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package logger
package main

import (
"strings"
Expand Down

0 comments on commit 6e2d6d6

Please sign in to comment.