-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: lot's of internals had been changed.
- Loading branch information
Showing
15 changed files
with
347 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env node | ||
|
||
const Consola = require('./src/cjs') | ||
|
||
const reporters = [ | ||
'FancyReporter', | ||
'BasicReporter', | ||
'JSONReporter', | ||
'WinstonReporter' | ||
] | ||
|
||
Consola.level = 5 | ||
|
||
for (const reporter of reporters) { | ||
Consola.log(reporter, '-----------------------') | ||
|
||
const consola = Consola.create({ | ||
reporters: [new Consola[reporter]()] | ||
}) | ||
|
||
for (let type of Object.keys(consola.types).sort()) { | ||
consola[type](`A message with consola.${type}()`) | ||
} | ||
|
||
consola.info('Consola can format JSON values too', { | ||
name: 'Cat', | ||
color: '#454545' | ||
}) | ||
|
||
consola.error(new Error('Something bad happened!')) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
455b6f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clarkdo @pimlie Your comments on it would be so useful.
455b6f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, am I correct its mostly interface changes and improvements but not so much new functionality or did I overlook something?
Here are my thoughts:
-v
or-q
on the command-line.deprecated
not depricated (in dutch depri is actually short for depressing, hope you dont feel that way! 😄 )Eg I currently use a type 'worker' and then set the workerId as scope (with a green color, so on an error you have the red text error and a green number of the worker). The reasoning behind this was that I dont wanted to print 10.000 times 'success', the colour green is more than enough. Maybe we could otherwise add a label property to logObj which overwrites the type name on printing?
nuxt-generate >/dev/null 2>nuxt.errors.log
.455b6f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pimlie Really cool ideas. Will try to implement most of them before release. About using Proxy, I have some doubt as I was planning to add browser support. But not really against it if gives us too many advantages.
455b6f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pi0 You probably know this already, but there is a polyfill for Proxy which supports the traps used here.
Although in this case its perfectly fine, I was mostly triggered by
log.bind(this)
. To me it looked like this is exactly a case for which Proxy was meant to be used. But I understand why you would want to keep using bind (eg implementing your own Consola instance would be a bit more difficult with Proxy)(btw, prefixing the log functions with a
_
in my example above is of course not necessary)455b6f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pimlie True about polyfill but it adds some overhead :( The binds will ensure that users won't call log functions with the context of another class and only will happen once creating consola instance (or custom ones with
create
)PS: please check your mailbox :D
455b6f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concerns with bind are mostly stemming from this SO question, but as said in this case its probably fine as no one in their right mind will create hundreds of log types.
Btw, should we also create helper methods to create a new global consola instance? Something like the following. Using replace-with should keep the initial reference so you wouldnt need to clear the module cache and then explictly use require instead of es6 imports.