-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds support for generating machine readable logs (#124)
* feat: adds support for generating machine readable logs Adds support for generating machine readable logs as JSON objects through the Adze configuration. Also resolves some underlying problems with the timeNow modifier where it was being applied only when a label was assigned to a log. timeNow no longer requires a label.
- Loading branch information
Showing
32 changed files
with
1,427 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Machine Readable Logs | ||
|
||
When working with your logs, typically in a production environment, the best practice is to generate logs as JSON objects. By generating them as JSON objects it makes them simpler to index, search, and sort at a later time. Adze supports this out of the box through the [`machineReadable` configuration property](#configuration). When this is enabled, all logs will cease printing in a user-friendly human-readable format and print to the console as JSON objects. These objects will contain all of the information that would normally be present in a human-readable log. | ||
|
||
## Configuration | ||
|
||
To enable machine readable JSON logs you must activate it through Adze configuration. | ||
|
||
```javascript | ||
import adze from 'adze'; | ||
|
||
adze({ machineReadable: true }).log('This log will be generated as JSON.'); | ||
``` | ||
|
||
## Common Usage | ||
|
||
The example above for configuring a machine readable log would only cause that single log that is defined to be machine readable. Not only that, but this log would also always be machine readable. This obviously is not the behavior we are after, so how can we set up our application to become machine readable in production environments? Let's look at an example using node environment variables: | ||
|
||
```javascript | ||
import adze from 'adze'; | ||
|
||
// When process.env.production is set to "true", we will | ||
// set the machineReadable property to true. | ||
const cfg = { | ||
machineReadable: process.env.environment === 'production' | ||
}; | ||
|
||
// We'll seal our configuration into a new log factory named logger | ||
const logger = adze(cfg).seal(); | ||
|
||
// Now we'll export our new logger for use throughout our application. | ||
export default logger; | ||
``` | ||
|
||
Now, as we import and use our logger throughout our application, when our environment is not 'production' we will have human readable logs. When our environment is production all logs will now be generated as machine readable JSON. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.