Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align output when using multiple scopes #49

Open
brandonweiss opened this issue Jun 29, 2018 · 3 comments
Open

Align output when using multiple scopes #49

brandonweiss opened this issue Jun 29, 2018 · 3 comments
Labels
feature request Request for a new feature

Comments

@brandonweiss
Copy link

brandonweiss commented Jun 29, 2018

Is your feature request related to a problem? Please describe.

Much of the logger output is aligned to columns. You can see it in screenshots in the README.

However scopes are not, which looks weird and seems inconsistent.

Describe the solution you'd like

Right now each instance only knows about one scope, so it wouldn't know what the maximum possible scope length is in order to add the right amount of padding. But there are a few ways around this. We could pass in all the scopes to each instance. It’s a little gross. Or one instance could be responsible for multiple scopes. That would require altering the interface a bit. Something like:

const { Signale } = require("signale")

const options = {
  scopes: ["server", "client"]
}

const logger = new Signale(options)
logger.server.start("Listening")
logger.client.start("Connecting")

If you're using multiple scopes you might have already created a similar interface yourself to simplify usage. For example, I don’t re-instantiate new instances with the scope I need in different parts of my application. I have one module that contains all the instances, each with their own scope, and then I access the one I need, much like in the example above.

@klaudiosinani klaudiosinani added the feature request Request for a new feature label Jul 3, 2018
@brandonweiss
Copy link
Author

brandonweiss commented Jul 22, 2018

This is sort of a separate issue, although it’s related. Even if the scopes are the same length, the longest label is calculated per-instance, causing the last column to not align.

screen shot 2018-07-22 at 7 58 27 am

What are your thoughts? Is this something you want to see fixed/handled? Or are you not interested?

I came up with a third way of handling this that might work. It might not necessitate changing the interface at all. Because Node modules are cached, static properties are effectively shared. So I think when a new instance is created, we could append the options to some static property, then rather than looking in the current instance to determine longest line length for scope, label, etc, we'd look in the static property.

Does that make sense? Thoughts?

@klaudiosinani
Copy link
Owner

klaudiosinani commented Aug 5, 2018

In general, it is easier to visually distinguish messages originating from the same scope/logger, due to their unique alignment, when mixed with a large number of messages originating from different scopes/loggers. A nice example is the log output that semantic-release emits.

But this could definitely be useful, we could add a couple of options, to align all messages across all instances or scopes, without them, of course, having to be mutually exclusive : )

@brandonweiss
Copy link
Author

@klauscfhq I just opened a PR for the first issue. Let me know what you think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

2 participants