Skip to content

Commit 2f14a27

Browse files
committed
Don’t warn by default
1 parent 95c40b4 commit 2f14a27

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Add to your `gatsby-config.js` (all options are optional; defaults shown here):
7070
}) => '',
7171
extensionDataDirectory: // Absolute path to the directory where extensions will be downloaded. Defaults to inside node_modules.
7272
path.resolve('extensions'),
73+
logLevel: 'error' // Set to 'warn' to debug if something looks wrong
7374
}
7475
}]
7576
}

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"json5": "^2.1.0",
5050
"lodash.escape": "^4.0.1",
5151
"lodash.uniq": "^4.5.0",
52+
"loglevel": "^1.6.3",
5253
"oniguruma": "^7.2.0",
5354
"plist": "^3.0.1",
5455
"unist-util-visit": "^1.4.0",

src/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @ts-check
22
const fs = require('fs');
33
const path = require('path');
4+
const logger = require('loglevel');
45
const visit = require('unist-util-visit');
56
const escapeHTML = require('lodash.escape');
67
const lineHighlighting = require('./lineHighlighting');
@@ -20,14 +21,14 @@ const styles = fs.readFileSync(path.resolve(__dirname, '../styles.css'), 'utf8')
2021
* @param {string} rootScopeName
2122
*/
2223
function warnMissingLanguageFile(missingScopeName, rootScopeName) {
23-
console.warn(`No language file was loaded for scope '${missingScopeName}' (requested by '${rootScopeName}').`);
24+
logger.warn(`No language file was loaded for scope '${missingScopeName}' (requested by '${rootScopeName}').`);
2425
}
2526

2627
/**
2728
* @param {string} lang
2829
*/
2930
function warnUnknownLanguage(lang) {
30-
console.warn(
31+
logger.warn(
3132
`Encountered unknown language '${lang}'. If '${lang}' is an alias for a supported language, ` +
3233
`use the 'languageAliases' plugin option to map it to the canonical language name.`
3334
);
@@ -120,6 +121,7 @@ function getStylesFromSettings(settings) {
120121
* @property {boolean=} injectStyles
121122
* @property {(colorValue: string, theme: string) => string=} replaceColor
122123
* @property {string=} extensionDataDirectory
124+
* @property {'trace' | 'debug' | 'info' | 'warn' | 'error'=} logLevel
123125
*/
124126

125127
function createPlugin() {
@@ -140,9 +142,11 @@ function createPlugin() {
140142
getLineClassName = () => '',
141143
injectStyles = true,
142144
replaceColor = x => x,
143-
extensionDataDirectory = path.resolve(__dirname, '../lib/extensions')
145+
extensionDataDirectory = path.resolve(__dirname, '../lib/extensions'),
146+
logLevel = 'error'
144147
} = {}
145148
) {
149+
logger.setLevel(logLevel);
146150
/** @type {Record<string, string>} */
147151
const stylesheets = {};
148152
const nodes = [];

0 commit comments

Comments
 (0)