Skip to content

Commit c650cca

Browse files
committed
wip
1 parent 0eaf456 commit c650cca

File tree

4 files changed

+498
-416
lines changed

4 files changed

+498
-416
lines changed

logger.md

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,12 @@ The logging utility coming with Supercharge is configurable to make it seamless
88

99

1010
## Configuraiton
11-
The configuration file for the logger is located at `config/logging.js` containing the default log driver and channels. You can configure each log channel to your own needs.
11+
Tba.
1212

13-
The default log driver is `console` printing everything to your terminal. When using the `file` driver, you may adjust the log file name which defaults to `app.log` and is located in `storage/logs/app.log`
1413

14+
### Available Log Drivers
15+
Tba.
1516

16-
### Available Drivers
17-
Supercharge uses a driver-based approach for logging. A driver represents a single channel or multiple channels. A channel itself describes the destiation for log messages. Here’s a list of available logging drivers and the related log channels:
18-
19-
| Channel Driver | Description |
20-
|----------------- |------------------- |
21-
| `stacked` | Logging to all available channels: `console` and `file` |
22-
| `console` | Logging all messages to the terminal |
23-
| `file` | Logging all messages to a dedicated log file |
24-
25-
26-
```info
27-
At this point, you can’t configure the stacked logger to exclude a specific channel. It will log to all available channels. This is very likely to change in future releases.
28-
```
2917

3018
## Using the Logger
3119
The logging utility is part of the Supercharge framework. It provides methods for seven different log levels:
@@ -44,29 +32,5 @@ Logger.silly(message)
4432
The logger provides a method corresponding to the supported log levels.
4533

4634

47-
#### Logging Context Data
48-
Use the logger anywhere in your application. Supercharge ensures to initialize the logger when starting your application. For example, you may log an `info` message in your routes. Add context information like an ID with the help of template strings:
49-
50-
```js
51-
const Post = require('../models/post')
52-
const Logger = require('@supercharge/framework/logging')
53-
54-
module.exports = {
55-
method: 'GET',
56-
path: '/post/{id}',
57-
handler: (request, h) => {
58-
const id = request.params.id
59-
60-
Logger.info(`Showing blog post with ID: ${id}`)
61-
62-
return h.view('blog/post', {
63-
post: await Post.findById(id)
64-
})
65-
}
66-
```
67-
68-
You may also pass context data to the log message using the [`sprintf`](https://en.wikipedia.org/wiki/Printf_format_string) syntax. Both channels, console and file, support the `sprintf` syntax format for all log levels. Here’s an example of a debug message containing the details about incoming request parameters:
69-
70-
```js
71-
Logger.debug(`Showing blog post with params: %j`, request.params)
72-
```
35+
### Logging Context Data
36+
Tba.

logger.org.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Logging
2+
3+
4+
## Introduction
5+
Logging allows you to provide transparency in your application. If you want to learn more about the processing and details of your application parts, logging is a good way. Supercharge provides a solid logger using the [Winston](https://github.com/winstonjs/winston) logging library.
6+
7+
The logging utility coming with Supercharge is configurable to make it seamless for you to log to different destinations, like the console or a log file.
8+
9+
10+
## Configuraiton
11+
The configuration file for the logger is located at `config/logging.js` containing the default log driver and channels. You can configure each log channel to your own needs.
12+
13+
The default log driver is `console` printing everything to your terminal. When using the `file` driver, you may adjust the log file name which defaults to `app.log` and is located in `storage/logs/app.log`
14+
15+
16+
### Available Drivers
17+
Supercharge uses a driver-based approach for logging. A driver represents a single channel or multiple channels. A channel itself describes the destiation for log messages. Here’s a list of available logging drivers and the related log channels:
18+
19+
| Channel Driver | Description |
20+
|----------------- |------------------- |
21+
| `stacked` | Logging to all available channels: `console` and `file` |
22+
| `console` | Logging all messages to the terminal |
23+
| `file` | Logging all messages to a dedicated log file |
24+
25+
26+
```info
27+
At this point, you can’t configure the stacked logger to exclude a specific channel. It will log to all available channels. This is very likely to change in future releases.
28+
```
29+
30+
## Using the Logger
31+
The logging utility is part of the Supercharge framework. It provides methods for seven different log levels:
32+
33+
```js
34+
const Logger = require('@supercharge/framework/logging')
35+
36+
Logger.error(message)
37+
Logger.warn(message)
38+
Logger.info(message)
39+
Logger.verbose(message)
40+
Logger.debug(message)
41+
Logger.silly(message)
42+
```
43+
44+
The logger provides a method corresponding to the supported log levels.
45+
46+
47+
#### Logging Context Data
48+
Use the logger anywhere in your application. Supercharge ensures to initialize the logger when starting your application. For example, you may log an `info` message in your routes. Add context information like an ID with the help of template strings:
49+
50+
```js
51+
const Post = require('../models/post')
52+
const Logger = require('@supercharge/framework/logging')
53+
54+
module.exports = {
55+
method: 'GET',
56+
path: '/post/{id}',
57+
handler: (request, h) => {
58+
const id = request.params.id
59+
60+
Logger.info(`Showing blog post with ID: ${id}`)
61+
62+
return h.view('blog/post', {
63+
post: await Post.findById(id)
64+
})
65+
}
66+
```
67+
68+
You may also pass context data to the log message using the [`sprintf`](https://en.wikipedia.org/wiki/Printf_format_string) syntax. Both channels, console and file, support the `sprintf` syntax format for all log levels. Here’s an example of a debug message containing the details about incoming request parameters:
69+
70+
```js
71+
Logger.debug(`Showing blog post with params: %j`, request.params)
72+
```

0 commit comments

Comments
 (0)