Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
Add example logger statements in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
binarylogic committed Feb 14, 2017
1 parent a08600f commit 839a343
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

Still logging raw text? Timber is a complete *structured* logging solution that you can setup in
minutes. It goes beyond traditional log management by focusing on data quality and modern
developer experiences.
developer standards.

High quality logs, [a modern beautiful interface](https://timber.io), simple setup,
High quality logs, [a modern UX-first interface](https://timber.io), simple setup,
zero-maintenance, 6-month retention, and sane prices are just a few of the benefits Timber
offers.

Expand Down Expand Up @@ -122,6 +122,8 @@ Use `Logger` as normal:

```elixir
logger.info("My log message")

# => My log message @timber.io {"level": "info", "context": {...}}
```

Timber will never deviate from the public `::Logger` interface in *any* way.
Expand All @@ -137,6 +139,8 @@ Timber will never deviate from the public `::Logger` interface in *any* way.
```ruby
Logger.warn message: "Payment rejected", type: :payment_rejected,
data: {customer_id: "abcd1234", amount: 100, reason: "Card expired"}

# => Payment rejected @timber.io {"level": "warn", "event": {"payment_rejected": {"customer_id": "abcd1234", "amount": 100, "reason": "Card expired"}}, "context": {...}}
```

2. Log a Struct (recommended)
Expand All @@ -150,6 +154,8 @@ Timber will never deviate from the public `::Logger` interface in *any* way.
def type; :payment_rejected; end
end
Logger.warn PaymentRejectedEvent.new("abcd1234", 100, "Card expired")

# => Payment rejected @timber.io {"level": "warn", "event": {"payment_rejected": {"customer_id": "abcd1234", "amount": 100, "reason": "Card expired"}}, "context": {...}}
```

* `:type` is how Timber classifies the event, it creates a namespace for the data you send.
Expand All @@ -164,8 +170,13 @@ send, and make it easier to search, graph, alert, etc.

```ruby
logger.info({key: "value"})
# => {"key": "value"}

logger.info('{"key": "value"}')
# => {"key": "value"}

logger.info('key=value')
# => key=value
```

---
Expand All @@ -184,8 +195,10 @@ value.

```ruby
Timber::CurrentContext.with({type: :build, data: {version: "1.0.0"}}) do
logger.info("This message will include the wrapped context")
logger.info("My log message")
end

# => My log message @timber.io {"level": "info", "context": {"build": {"version": "1.0.0"}}}
```

This adds data to the context keyspaced by `build`.
Expand All @@ -201,8 +214,10 @@ value.
end
build_context = BuildContext.new("1.0.0")
Timber::CurrentContext.with(build_context) do
logger.info("This message will include the wrapped context")
logger.info("My log message")
end

# => My log message @timber.io {"level": "info", "context": {"build": {"version": "1.0.0"}}}
```

</p></details>
Expand Down

0 comments on commit 839a343

Please sign in to comment.