Activities

nevf

nevf posted a new question

consola β€’

How to use FancyReporter etc.

I have consola working with the default BasicReporter which is included in the JS file, however I can't work out how to use other reporters such as FancyReporter. None of the other reporters are installed using npm i consola.

Also should tags be displayed with BasicReporter? If so I can't get them to work.

Finally it would be great to see better documentation and an article on usage with examples would also be most welcome..

rkgrep

rkgrep posted a new feature request

consola β€’

idea TypeScript definitions

What problem does this feature solve?

I want to use consola in an express app written in TS, but for some reason definitions are excluded from final build published to NPM

Tom-Bonnike

Tom-Bonnike posted a new bug report

consola β€’

bug Maximum call stack size exceeded in browser?

Version

2.2.3

Reproduction link

https://codesandbox.io/s/vj522nv827

Steps to reproduce

  • Use wrapAll
  • Use any console.* method after that

What is expected ?

The log is enhanced

What is actually happening?

  • The page crashes because of maximum call stack size exceeded.
  • The browser reporter keeps on calling itself.
pi0

pi0 posted a new question

consola β€’

consola v3 proposal
  • Use Proxy instead of creating closures for each log type. This allows using arbitrary log types and less overhead of tagged loggers and easier mocking
  • Find a way to make tagged loggers more lightweight when using withTag
  • Deprecate withDefaults and create (Keep for legacy but create a new class instance`
  • Support logs with timer (Using a token?)
  • Seperate <type>(logOjb) from <type>(args. (How?)
pimlie

pimlie resolved the question #c35

consola β€’

How to use custom consola instance with nuxt (probably esm/cjs issue)

It was partly too late I guess, I couldnt get it too work in nuxt-generate-cluster because there was still another Nuxt es6 import I missed it seems. After double checking to change all the nuxt imports to require's and add the cache delete after my own global.consola assignment it also works in the full project.

@pi0 @clarkdo Do you regards this a documentation issue or do you want to have a go at this to find a 'sexier' solution? If docs, I am happy to add something to the readme.

pimlie

pimlie posted a new question

consola β€’

Why no auto-mocking with jest?

Why isnt it possibile (according to the docs) to auto-mocking consola with jest? The below example seems to work fine.
Also jest already supports methods for checking arguments, the following example does more or less the same as the current example. But as you know more than me, maybe I am missing something?

import consola from 'consola'

jest.mock('consola')

describe('consola', () => {
  beforeAll(() => {
    consola.wrapAll()
  })

  beforeEach(() => {
    jest.clearAllMocks()
  })

  test('is mocked', () => {
    consola.log('your message')

    expect(consola.log).toHaveBeenCalledWith('your message')
    expect(consola.log).toHaveBeenCalledTimes(1)
  })

  test('is mocked 2', () => {
    consola.log('your message 2')

    expect(consola.log).toHaveBeenCalledWith(expect.stringMatching(/message \d$/))
    expect(consola.log).toHaveBeenCalledTimes(1)
  })
})
Bjornskjald

Bjornskjald posted a new feature request

consola β€’

idea Allow choosing util.format depth

What problem does this feature solve?

For large nested object (eg. Discord.js classes) consola doesn't have a level limit.

What does the proposed changes look like?

Add depth property to formatWithOptions

manniL

manniL posted a new feature request

consola β€’

idea docs: improve mocking guide

What problem does this feature solve?

It'd be great to have a few examples on how to mock consola (default, but also withScope) ☺️

We already have examples in the README, but a few more words to each wouldn't be bad ☺️

pimlie

pimlie posted a new question

consola β€’

How to use custom consola instance with nuxt (probably esm/cjs issue)

Although the docs say that consola is a global object, I cant get it too work correctly it seems. I have narrowed it down to module.exports which are cached.

<summary>A basic example is this</summary>

// run as <file>.js
const { Consola, FancyReporter } = require('consola')

consola = new Consola({
  level: 4,
  reporters: [ new FancyReporter ],
  types: {
    warn: {
      level: 2,
      color: 'blue'
    },
  }
})

global.consola = consola

const consola2 = require('consola')
consola2.warn('yellow warning about nothing')

delete require.cache[require.resolve('consola')]

const consola3 = require('consola')
consola3.warn('blue warning about nothing')

The last consola3.warn is only blue when you delete the require.cache. This is because the first require already triggered node to cache the consola module, and as all other requires resolve to the same module/file it just uses the cached file.

The problem comes with esm modules like Nuxt has, the delete require.cache doesnt work there because during transpiling all requires are moved to the top of the file. Besides that, the delete require.cache trick only works when exactly:

  • the delete happens after the custom global.consola assigment
  • the require of Nuxt also happens after the custom global.consola assigment (and after the delete ofc)

<summary>Require Nuxt works (both lines blue)</summary>

// run with node -r esm <file.js>
console.log('mix -> works')
import consola from './inc/consola'
delete require.cache[require.resolve('consola')]

const { Nuxt } = require('nuxt')
const nuxt = new Nuxt()
nuxt.hook('render:context', () => {})
consola.warn('blue warning about nothing')

The following doesnt work:

<summary>Import Nuxt doesnt work (Nuxt's warning is yellow but should be blue)</summary>

// run with node -r esm <file.js>
import consola from './inc/consola'
delete require.cache[require.resolve('consola')]
import { Nuxt } from 'nuxt'

const nuxt = new Nuxt()
nuxt.hook('render:context', () => {})
consola.warn('blue warning about nothing')

<summary>inc/consola.js</summary>

import { Consola, FancyReporter } from 'consola'

let consola = global && global.consola

if (!consola) {
  consola = new Consola({
    level: 4,
    types: {
      warn: {
        level: 2,
        color: 'blue'
      },
    }
  })

  consola.add(new MyReporter())

  global.consola = consola
}

export default consola

Is it just too late and am I missing something obvious here? Any help / pointers are appreciated :)

Fyi, I am looking into this because for nuxt-generate-cluster I want all workers to push their log messages to the master so only the master has logging output. This does work nicely with a custom reporter, but I cant seem to capture the success: Generated /users/2 messages from within Nuxt.Generator. At least not without dirty tricks like re-assigning all object props again tp the global.consola object and stubbing the success method.

kazumi-kondo-forgevision

kazumi-kondo-forgevision posted a new question

consola β€’

ci-info module throw error for "process is not defined" again

please reopen this issue.
https://github.com/nuxt/consola/issues/19


"@nuxtjs/axios": {

"version": "5.3.1",

"consola": {

"version": "1.4.1",

"std-env": {

"version": "1.3.1",

"is-ci": {

"version": "1.1.0",

"ci-info": {

"version": "1.1.3",

abegehr

abegehr posted a new question

consola β€’

Can consola be used in components?

I'm using consola in a component by importing directly after the script-tag:

<script>
const consola = require("consola");
…

And then I use consola.start("Starting"); later on in a method.

I get the following error:

client.js:533 [nuxt] Error while initializing app ReferenceError: process is not defined
at Object../nodemodules/ci-info/index.js (index.js:3) at webpackrequire (bootstrap 9ce993297b8f99b86341:712)
at fn (bootstrap 9ce993297b8f99b86341:117)
at Object../nodemodules/is-ci/index.js (index.js:3) at webpackrequire (bootstrap 9ce993297b8f99b86341:712)
at fn (bootstrap 9ce993297b8f99b86341:117)
at Object.<anonymous> (index.js:1)
at Object../nodemodules/std-env/index.js (index.js:18) at webpackrequire (bootstrap 9ce993297b8f99b86341:712)
at fn (bootstrap 9ce993297b8f99b86341:117)

tim-yao

tim-yao posted a new bug report

consola β€’

bug ci-info module throw error for "process is not defined"

Version

1.3.0

Reproduction link

https://codepen.io/timyaodpc/pen/bMyazm

Steps to reproduce

Use it in Nuxt/plugins/myplugin.js.

It all works but in browser console it give me a error says "process is not defined". Error points to "ci-info" module first line which tries to use process.env.

I can see ci-info is a dependency of consola as below:

└─┬ [email protected]
└─┬ [email protected]
└─┬ [email protected]
└── [email protected]

I now have to add isServer condition on const consola = require('consola'). Otherwise it breaks the client side.

What is expected ?

Browser should no error in console.

What is actually happening?

A error from ci-info says "process is not defined".

index.js:3 Uncaught ReferenceError: process is not defined
at Object../nodemodules/ci-info/index.js (index.js:3) at webpackrequire (bootstrap 20212f6dd5b287d60bc9:712)
at fn (bootstrap 20212f6dd5b287d60bc9:117)
at Object../nodemodules/is-ci/index.js (index.js:3) at webpackrequire (bootstrap 20212f6dd5b287d60bc9:712)
at fn (bootstrap 20212f6dd5b287d60bc9:117)
at Object.<anonymous> (index.js:1)
at Object../nodemodules/std-env/index.js (index.js:18) at webpackrequire (bootstrap 20212f6dd5b287d60bc9:712)
at fn (bootstrap 20212f6dd5b287d60bc9:117)

Additional comments?

Is Consola can only be used in server side js?
The consola code index.js first line imported std-env which can only used in server side.
https://github.com/nuxt/consola/blob/master/src/index.js#L1
Not sure which is the best way to use it in Nuxt and maybe it's a bug?

nikolaynesov

nikolaynesov posted a new question

consola β€’

Please remove the issue

Please remove it

hqqxxf

hqqxxf posted a new bug report

consola β€’

bug The page returned to the home page on wechat

Version

1.4.0

Reproduction link

https://jsfiddle.net/hqqxxf/edLsh8sL/

Steps to reproduce

in router '/a', it has a link to '/b', when I returned in '/b', The page returned to the home page('/') , and I found not the static resources request when returned.

What is expected ?

returned to the last page(router '/a')

What is actually happening?

returned to the home page(router '/' or 404)

ujjwalguptaofficial

ujjwalguptaofficial posted a new question

consola β€’

override route based on the pages folder

Let say In pages folder I have two folder - temp1 and temp2. So url will be -

"localhost/temp1/" and "localhost/temp2/ "

I want to overload url for temp2 folder and make it like - "localhost/" . I mean make it like the content of temp2 folder is in root

chenfangyi931

chenfangyi931 posted a new question

consola β€’

The vuex state can not be modified within the Axios interceptor

TIMζˆͺε›Ύ20180506183037.png

kuangyazhou

kuangyazhou posted a new question

consola β€’

asyncData how to send multi request

in my code

async asyncData(){
const [a,b]=await Promise.all( await axios.get('/api/users'), await axios.get('/api/list') )
return {
users:a,
list:b,
}
}

why this mehtod not work ??
In my view ,i won't get the data users and list

what is the right writing

Jeromearsene

Jeromearsene posted a new question

consola β€’

Object is undefined if not stringified (JSON.stringify)

I have an object to log.

I do this:

    console.log(professionnalInfos);
    logger.info(professionnalInfos);
    logger.info(JSON.stringify(professionnalInfos));

Result:

{ siren: '1111111', phone: '0511111111' }
β„Ή info undefined
β„Ή info {"siren":"1111111","phone":"0511111111"}

I think undefined is counter intuitive. No ?

kuangyazhou

kuangyazhou posted a new question

consola β€’

how can i debugger my code in development

now ,i'm useing the nuxt-express templte 。in chrome ,i open the network ,how can I debugger my code by the method set point

Jeromearsene

Jeromearsene posted a new question

consola β€’

Problem error log color invisible

With my iterm configuration, I have this problem:
capture d ecran 2018-05-03 a 11 01 05

Error's details exist. If I select details, you can see this:
capture d ecran 2018-05-03 a 11 01 19

An idea for custom color ? Or other idea who can help me.

Thank you