mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-07 09:22:27 +00:00
refactor: use consola for all console stuff
This commit is contained in:
parent
6894cd5026
commit
25741f5a1f
@ -76,7 +76,7 @@ export default class Generator {
|
|||||||
...args
|
...args
|
||||||
)
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Could not resolve routes') // eslint-disable-line no-console
|
logger.error('Could not resolve routes')
|
||||||
throw e // eslint-disable-line no-unreachable
|
throw e // eslint-disable-line no-unreachable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import consola from 'consola'
|
||||||
|
|
||||||
import Youch from '@nuxtjs/youch'
|
import Youch from '@nuxtjs/youch'
|
||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
|
|
||||||
|
const logger = consola.withScope('nuxt:error')
|
||||||
|
|
||||||
export default function errorMiddleware(err, req, res, next) {
|
export default function errorMiddleware(err, req, res, next) {
|
||||||
// ensure statusCode, message and name fields
|
// ensure statusCode, message and name fields
|
||||||
err.statusCode = err.statusCode || 500
|
err.statusCode = err.statusCode || 500
|
||||||
@ -11,7 +14,7 @@ export default function errorMiddleware(err, req, res, next) {
|
|||||||
|
|
||||||
// We hide actual errors from end users, so show them on server logs
|
// We hide actual errors from end users, so show them on server logs
|
||||||
if (err.statusCode !== 404) {
|
if (err.statusCode !== 404) {
|
||||||
console.error(err) // eslint-disable-line no-console
|
logger.error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendResponse = (content, type = 'text/html') => {
|
const sendResponse = (content, type = 'text/html') => {
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import generateETag from 'etag'
|
import generateETag from 'etag'
|
||||||
import fresh from 'fresh'
|
import fresh from 'fresh'
|
||||||
|
import consola from 'consola'
|
||||||
|
|
||||||
import { getContext } from '../../common/utils'
|
import { getContext } from '../../common/utils'
|
||||||
|
|
||||||
|
const logger = consola.withScope('nuxt:middleware')
|
||||||
|
|
||||||
export default async function nuxtMiddleware(req, res, next) {
|
export default async function nuxtMiddleware(req, res, next) {
|
||||||
// Get context
|
// Get context
|
||||||
const context = getContext(req, res)
|
const context = getContext(req, res)
|
||||||
@ -103,7 +106,7 @@ export default async function nuxtMiddleware(req, res, next) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (context && context.redirected) {
|
if (context && context.redirected) {
|
||||||
console.error(err) // eslint-disable-line no-console
|
logger.error(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@ import compression from 'compression'
|
|||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
import { createBundleRenderer } from 'vue-server-renderer'
|
import { createBundleRenderer } from 'vue-server-renderer'
|
||||||
import Debug from 'debug'
|
|
||||||
import connect from 'connect'
|
import connect from 'connect'
|
||||||
import launchMiddleware from 'launch-editor-middleware'
|
import launchMiddleware from 'launch-editor-middleware'
|
||||||
|
import consola from 'consola'
|
||||||
|
|
||||||
import { isUrl, waitFor, timeout } from '../common/utils'
|
import { isUrl, waitFor, timeout } from '../common/utils'
|
||||||
import defaults from '../common/nuxt.config'
|
import defaults from '../common/nuxt.config'
|
||||||
@ -18,8 +18,7 @@ import MetaRenderer from './meta'
|
|||||||
import errorMiddleware from './middleware/error'
|
import errorMiddleware from './middleware/error'
|
||||||
import nuxtMiddleware from './middleware/nuxt'
|
import nuxtMiddleware from './middleware/nuxt'
|
||||||
|
|
||||||
const debug = Debug('nuxt:render')
|
const logger = consola.withScope('nuxt:render')
|
||||||
debug.color = 4 // Force blue color
|
|
||||||
|
|
||||||
let jsdom = null
|
let jsdom = null
|
||||||
|
|
||||||
@ -290,7 +289,7 @@ export default class Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Log rendered url
|
// Log rendered url
|
||||||
debug(`Rendering url ${url}`)
|
logger.debug(`Rendering url ${url}`)
|
||||||
|
|
||||||
// Add url and isSever to the context
|
// Add url and isSever to the context
|
||||||
context.url = url
|
context.url = url
|
||||||
@ -400,11 +399,11 @@ export default class Renderer {
|
|||||||
try {
|
try {
|
||||||
jsdom = this.nuxt.requireModule('jsdom')
|
jsdom = this.nuxt.requireModule('jsdom')
|
||||||
} catch (e) /* istanbul ignore next */ {
|
} catch (e) /* istanbul ignore next */ {
|
||||||
/* eslint-disable no-console */
|
consola.error(`
|
||||||
console.error('Fail when calling nuxt.renderAndGetWindow(url)')
|
Fail when calling nuxt.renderAndGetWindow(url)
|
||||||
console.error('jsdom module is not installed')
|
jsdom module is not installed
|
||||||
console.error('Please install jsdom with: npm install --save-dev jsdom')
|
Please install jsdom with: npm install --save-dev jsdom
|
||||||
/* eslint-enable no-console */
|
`)
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -418,7 +417,7 @@ export default class Renderer {
|
|||||||
}
|
}
|
||||||
const jsdomErrHandler = err => { throw err }
|
const jsdomErrHandler = err => { throw err }
|
||||||
if (opts.virtualConsole !== false) {
|
if (opts.virtualConsole !== false) {
|
||||||
options.virtualConsole = new jsdom.VirtualConsole().sendTo(console)
|
options.virtualConsole = new jsdom.VirtualConsole().sendTo(consola)
|
||||||
// throw error when window creation failed
|
// throw error when window creation failed
|
||||||
options.virtualConsole.on('jsdomError', jsdomErrHandler)
|
options.virtualConsole.on('jsdomError', jsdomErrHandler)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user