Skip to content

Commit 0d2210c

Browse files
committed
Made log override optional, added prefix, docs
1 parent 56a0a60 commit 0d2210c

File tree

3 files changed

+80
-55
lines changed

3 files changed

+80
-55
lines changed

packages/content/test/config.js

Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,69 @@ const config = {
1212
},
1313
"sources": [
1414
{
15-
"id": "spaceships",
15+
"id": "dummyjson",
1616
"type": "json",
1717
"files": {
18-
"spaceships.json": "https://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&tags=spaceship",
19-
"rockets.json": "https://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&tags=rocket"
20-
},
21-
"strip": "services/feeds/",
22-
"imageTransforms": [
23-
{"scale": 0.75}
24-
]
25-
},
26-
{
27-
"id": "astronauts",
28-
"files": {
29-
"astronauts.json": "https://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&tags=astronauts"
30-
},
31-
"strip": "services/feeds/"
32-
},
33-
{
34-
"id": "strapiTest",
35-
"type": "strapi",
36-
"version": 3,
37-
"baseUrl": "http:localhost:1337/",
38-
"queries": ["poems"],
39-
"limit": 100,
40-
"maxNumPages": -1,
41-
"pageNumZeroPad": 0,
42-
},
43-
{
44-
"id": "contentfulTest",
45-
"type": "contentful",
46-
"space": "qc670l0h4zjf",
47-
"locale": "en-US",
48-
"filename": "content.json",
49-
"protocol": "https",
50-
"searchParams": {
51-
"limit": 1000,
52-
"include": 10
53-
},
54-
"contentTypes": [],
55-
"imageParams": {
56-
"f": "face",
57-
"fit": "crop",
58-
"w": 512,
59-
"h": 512
18+
"photos.json": "https://dummyjson.com/products"
6019
}
6120
},
62-
{
63-
"id": "airtableTest",
64-
"type": "airtable",
65-
"baseId": "apppsX7HeYHO7rMjd",
66-
"defaultView": "Grid view",
67-
"tables": ["data"],
68-
"keyValueTables": ["settings"],
69-
"appendLocalAttachmentPaths": true,
70-
}
21+
// {
22+
// "id": "spaceships",
23+
// "type": "json",
24+
// "files": {
25+
// "spaceships.json": "https://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&tags=spaceship",
26+
// "rockets.json": "https://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&tags=rocket"
27+
// },
28+
// "strip": "services/feeds/",
29+
// "imageTransforms": [
30+
// {"scale": 0.75}
31+
// ]
32+
// },
33+
// {
34+
// "id": "astronauts",
35+
// "files": {
36+
// "astronauts.json": "https://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&tags=astronauts"
37+
// },
38+
// "strip": "services/feeds/"
39+
// },
40+
// {
41+
// "id": "strapiTest",
42+
// "type": "strapi",
43+
// "version": 3,
44+
// "baseUrl": "http:localhost:1337/",
45+
// "queries": ["poems"],
46+
// "limit": 100,
47+
// "maxNumPages": -1,
48+
// "pageNumZeroPad": 0,
49+
// },
50+
// {
51+
// "id": "contentfulTest",
52+
// "type": "contentful",
53+
// "space": "qc670l0h4zjf",
54+
// "locale": "en-US",
55+
// "filename": "content.json",
56+
// "protocol": "https",
57+
// "searchParams": {
58+
// "limit": 1000,
59+
// "include": 10
60+
// },
61+
// "contentTypes": [],
62+
// "imageParams": {
63+
// "f": "face",
64+
// "fit": "crop",
65+
// "w": 512,
66+
// "h": 512
67+
// }
68+
// },
69+
// {
70+
// "id": "airtableTest",
71+
// "type": "airtable",
72+
// "baseId": "apppsX7HeYHO7rMjd",
73+
// "defaultView": "Grid view",
74+
// "tables": ["data"],
75+
// "keyValueTables": ["settings"],
76+
// "appendLocalAttachmentPaths": true,
77+
// }
7178
]
7279
};
7380

packages/launchpad/docs/logging.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ See: https://github.com/winstonjs/winston#creating-your-own-logger for all avail
4646
| <a name="module_log-manager.LogOptions+fileOptions">`fileOptions`</a> | <code>LogFileOptions</code>| <code>new LogFileOptions(fileOptions)</code> | Options for individual files and streams. |
4747
| <a name="module_log-manager.LogOptions+level">`level`</a> | <code>string</code>| <code>'info'</code> | The maximum log level to display in all default logs. |
4848
| <a name="module_log-manager.LogOptions+format">`format`</a> | <code>winston.Logform.Format</code>| <code>LogOptions.DEFAULT\_LOG\_FORMAT</code> | The format for how each line is logged. |
49+
| <a name="module_log-manager.LogOptions+overrideConsole">`overrideConsole`</a> | <code>boolean</code>| <code>true</code> | Route all console logs to the log manager. This helps<br>ensure that logs are routed to files and rotated properly.<br><br>This will also freeze the console object, so it can't be<br>modified further during runtime.<br><br>All console logs will be prefixed with `(console)`. |
4950

5051

5152
### LogFileOptions

packages/utils/lib/log-manager.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class LogOptions {
3838
fileOptions = new LogFileOptions(),
3939
level = 'info',
4040
format = LogOptions.DEFAULT_LOG_FORMAT,
41+
overrideConsole = true,
4142
...rest
4243
} = {}) {
4344
/**
@@ -68,6 +69,20 @@ export class LogOptions {
6869
*/
6970
this.format = format;
7071

72+
/**
73+
* Route all console logs to the log manager. This helps
74+
* ensure that logs are routed to files and rotated properly.
75+
*
76+
* This will also freeze the console object, so it can't be
77+
* modified further during runtime.
78+
*
79+
* All console logs will be prefixed with `(console)`.
80+
*
81+
* @type {boolean}
82+
* @default true
83+
*/
84+
this.overrideConsole = true;
85+
7186
Object.assign(this, rest);
7287
}
7388
}
@@ -180,8 +195,10 @@ class LogManager {
180195
new winston.transports.DailyRotateFile({ ...this._config.fileOptions, filename: this.getFilePath('launchpad-error', false), level: 'error'}),
181196
],
182197
});
183-
184-
this.overrideConsoleMethods();
198+
199+
if (this._config.overrideConsole) {
200+
this.overrideConsoleMethods();
201+
}
185202
}
186203

187204
/**
@@ -219,7 +236,7 @@ class LogManager {
219236
*/
220237
overrideConsoleMethods() {
221238
// Override console methods
222-
const logger = this.getLogger();
239+
const logger = this.getLogger('console');
223240
console.log = logger.info.bind(logger);
224241
console.info = logger.info.bind(logger);
225242
console.warn = logger.warn.bind(logger);

0 commit comments

Comments
 (0)