What am I doing wrong when injecting a logger to the Nuxt instance?
loglevel.client.js
import log from 'loglevel';
log.setLevel(process.env.LOG_LEVEL || 'debug');
export default ({ app }, inject) => {
inject('log', log);
log.debug('logger set up')
}
nuxt.config.js
plugins: [
'~/plugins/loglevel.client.js',
'~/plugins/api.js',
],
plugins\api.js
if (process.client) {
console.log('on client console')
this.$log.error('on client $log')
}
browser:
api.js?e568:4 on client console
08:22:26.456 api.js?e568:5 Uncaught TypeError: Cannot read properties of undefined (reading '$log')
at eval (api.js?e568:5:1)
at Module../plugins/api.js (app.js:1033:1)