Skip to content

Commit 2c947cb

Browse files
authored
Update Readme.md
Thanks to grammarly
1 parent 5045aec commit 2c947cb

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

co-log-json/Readme.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# co-log-json
22

3-
`co-log-json` allows to write structured logs in your application.
3+
`co-log-json` allows writing structured logs in your application.
44

5-
The library allows to add additional machine readable context to the log
6-
messages. I.e. each log message is a json object with a predefined structure
5+
The library allows adding additional machine-readable context to the log
6+
messages. I.e. each log message is a JSON object with a predefined structure
77
where additional user context can be added. Such logs can be easily indexed
8-
by external logs systems such as [graylog](https://www.graylog.org) or
8+
by external logs systems such as [Graylog](https://www.graylog.org) or
99
[Elastic search](https://www.elastic.co). The message logging is done using
10-
a special context, that keeps information about additional attributes.
11-
Such contexts forms a nested scope, and all messages in the score inherit provided
10+
a special context, that keeps the information about additional attributes.
11+
Such contexts form a nested scope, and all messages in the score inherit provided
1212
context:
1313

1414
```
@@ -22,26 +22,26 @@ context:
2222
```
2323

2424

25-
In other words this library takes two choices:
25+
In other words, this library takes two choices:
2626

2727
1. We write full context with each message.
28-
This approach allows to use external tools (like elastic-search) that can index message
28+
This approach allows using external tools (like elastic-search) that can index message
2929
without any additional work and information.
30-
Any message can be lost without affecting ability to decode other messages. Alternative
31-
approach could be emitting a list of events (possibly as a bytecode), such approach
30+
Any message can be lost without affecting the ability to decode other messages. An alternative
31+
approach could be emitting a list of events (possibly as a bytecode), such an approach
3232
is taken by the tracing libraries. It requires more works during reading and indexing
33-
logs, and in case in some logs are logs may render later ones unusable or lose some info.
33+
logs, and in the case in some logs are logs may render later ones unusable or lose some info.
3434

3535
2. We keep a state context so we don't need to attach context messages to each one.
36-
Alternative approach is extraction of the structure information from the message itself.
36+
An alternative approach is the extraction of the structure information from the message itself.
3737
This approach is taken in some structured logging libraries, it can provide better error
38-
messages. However it requires to think about the message context all the time (and developer
38+
messages. However, it requires to think about the message context all the time (and developer
3939
user may not even know all interesting context where the message will be used).
4040

4141

4242
# Using a library
4343

44-
In order to use a library you'll need to add `co-log-json` to the dependency list.
44+
To to use a library you'll need to add `co-log-json` to the dependency list.
4545

4646
```
4747
library.cabal
@@ -63,8 +63,8 @@ import System.IO (stderr)
6363

6464
main :: IO ()
6565
main = do
66-
-- First we need to setup log storing function:
67-
-- In order to emit logs we need to create a context.
66+
-- First, we need to set up log storing function:
67+
-- To emit logs we need to create a context.
6868
-- Context takes the action to store log and it's possible to
6969
-- attach additional information to it.
7070

@@ -100,24 +100,24 @@ main = do
100100
-- There are other helper functions list `logInfo`, `logNotice`, etc.
101101
```
102102

103-
Now let's discuss `LogStr` type. It exists in order to efficiently generate message without
104-
extra allocations that can be avoided. Basically it's just a [Text.Builder](http://hackage.haskell.org/package/text-1.2.4.0/docs/Data-Text-Lazy-Builder.html) though iternal
103+
Now let's discuss `LogStr` type. It exists to efficiently generate message without
104+
extra allocations that can be avoided. It's just a [Text.Builder](http://hackage.haskell.org/package/text-1.2.4.0/docs/Data-Text-Lazy-Builder.html) though internal
105105
representation may evolve in the future. `LogStr` allows message concatenation without allocating
106106
intermediate structures, so it allows efficient log building. For example line:
107107

108108
```haskell
109109
logDebug context $ "a" <> "b" <> "c"
110110
```
111111

112-
will write all text string "a", "b", "c" directy to the buffer, and can actually do more optimizations.
113-
So it's quite safe to use the librart even with a large amount of logs.
112+
will write all text string "a", "b", "c" directly to the buffer, and can do more optimizations.
113+
So it's quite safe to use the library even with a large number of logs.
114114

115115
The 'LogStr' type implement [IsString](http://hackage.haskell.org/package/base-4.14.0.0/docs/Data-String.html#t:IsString) instance it means that you can just write string literals
116116
and they will be treated as 'LogStr'. To concatenate two 'LogStr' you can use [`<>`](https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Semigroup.html#t:Semigroup) operation.
117117

118118
In addition you can convert any string lines that has [StringConv a T.Text](https://hackage.haskell.org/package/string-conv-0.1.2/docs/Data-String-Conv.html), i.e. can be converted
119119
to LogStr using `ls :: StringConv a T.Text => a -> LogStr`.
120-
Efficiency and safety of this convertion depends on the concrete instance implementation and is out
120+
Efficiency and safety of this conversion depends on the concrete instance implementation and is out
121121
of control of the package.
122122

123123
```haskell
@@ -129,7 +129,7 @@ very general `showLS :: Show a => a -> LogStr` method that will work for any typ
129129

130130
## Adding context.
131131

132-
But just writing json messages is not very interesting, we want to control the context of the message.
132+
But just writing JSON messages is not very interesting, we want to control the context of the message.
133133
In order to add user data to the context we can use `addContext :: PushContext -> LoggerEnv -> LoggerEnv`
134134
method.
135135

@@ -164,9 +164,9 @@ Function `sl :: ToJSON a => T.Text -> a -> PushContext` prepares update to the c
164164
It encodes user data to JSON. This is why we had to add type annotation to `1` otherwise GHC had
165165
no means to infer the type).
166166

167-
It's important that library does not perform any compacation of key-values, i.e.:
167+
It's important that the library does not perform any compaction of key-values, i.e.:
168168

169-
```
169+
```haskell
170170
logDebug (addContext (sl "user_id" 2) context1) "Who am I?"
171171
-- Will emit:
172172
-- ```
@@ -183,25 +183,25 @@ the codebase the log belongs to. It's kept separate fom the data, and it's possi
183183
use in library filtering (using [cfilter](https://kowainik.github.io/posts/2018-09-25-co-log#cfilter)) or filtering in external system.
184184

185185

186-
The described functionality is enough to perform logging. However it may worth discussing
187-
interporability with the rest of co-log ecosystem and ergonomics.
186+
The described functionality is enough to perform logging. However, it may worth discussing
187+
interoperability with the rest of co-log ecosystem and ergonomics.
188188

189-
## co-log interporability
189+
## co-log interoperability
190190

191-
co-log ecosystem works with "LogAction m a" and in the package we use "LogEnv" it means
191+
The co-log ecosystem works with "LogAction m a" and in the package, we use "LogEnv" it means
192192
that we are losing most of the benefits of the library and can't use a lot of utility
193-
functions. In order to improve the situation it's possible to convert LogEnv into
193+
functions. To improve the situation it's possible to convert LogEnv into
194194
`LogAction m (Severity,LogStr)` using function `unLogger`. Then we will have log action
195-
that will emit a message with the current context, but context will no longer be modifiable.
195+
that will emit a message with the current context, but the context will no longer be modifiable.
196196

197197
# Ergonomics
198198

199199
The package provides no ergonomic tools by default and it's important that `addContext` is a pure
200-
function. On the one hand it introduces a log of boilerplate code but on the other.
200+
function. On the one han,d it introduces a log of boilerplate code but on the other.
201201

202202
It allows to modify context even outside of the effectful computation for example with servant you may have:
203203

204-
```
204+
```haskell
205205
-- | Catalogue of items
206206
data CatalogueApi route = CatalogueApi
207207
{ _the_catalogue :: route :- Capture "catalogue_id" CatalogueId :> ToServantAPI Bar
@@ -230,7 +230,7 @@ handleItem ctx' catalogue_id = ItemApi ...
230230

231231
So we can build computation that we will execute later while modifying the context.
232232

233-
On the other hand it we can always wrap this pure function into an effect system
234-
of choice be it either handle pattern or readert or mtl or free-monad or effect system.
235-
This library does not target any particular solution and do not want to introduce
233+
On the other hand, we can always wrap this pure function into an effect system
234+
of choice be it either handle pattern or readert or MTL or effect system.
235+
This library does not target any particular solution and want to introduce
236236
neither additional dependencies nor additional restrictions on the user.

0 commit comments

Comments
 (0)