11// @ts -check
22const fs = require ( 'fs' ) ;
33const path = require ( 'path' ) ;
4+ const logger = require ( 'loglevel' ) ;
45const visit = require ( 'unist-util-visit' ) ;
56const escapeHTML = require ( 'lodash.escape' ) ;
67const lineHighlighting = require ( './lineHighlighting' ) ;
@@ -20,14 +21,14 @@ const styles = fs.readFileSync(path.resolve(__dirname, '../styles.css'), 'utf8')
2021 * @param {string } rootScopeName
2122 */
2223function 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 */
2930function 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
125127function 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