Skip to content

Log() or Debug() function #1459

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

Closed
Soviut opened this issue Aug 1, 2013 · 7 comments
Closed

Log() or Debug() function #1459

Soviut opened this issue Aug 1, 2013 · 7 comments

Comments

@Soviut
Copy link

Soviut commented Aug 1, 2013

As LESS frameworks become more common, it gets harder and harder to determine if complex calculations are being evaluated as expected.

I propose a debugging function that prints to either the node console during compilation or the browser console if being run in the browser. Something simple like the console.log() we're all familiar with. If log() is too close to Math.log() then perhaps debug() is less ambiguous.

Ideally, multiple values could be output at once and the line number the function was called on would be very useful.

@Soviut
Copy link
Author

Soviut commented Aug 28, 2013

So I'm tempted to start working on this as I know the functions are separated into a convenient functions.js file, however, I'm wondering what sort of behaviour I should use.

I think the debug() function should act as a pass through. Whatever value is passed in will be returned, allowing it be used inline with an attribute:

div {
    width: debug(5px + 2px);
}

This would print something like DEBUG Line 2: 7px to the web console in the browser or to STDOUT during compilation. Printing what column the debug happened on might also be useful for cases where multiple debug statements are nested within each other, for example:

div {
    width: debug(5px + debug(10px - 5px));
}

Some additional work may be necessary for dealing with colours; Specifically how they should be displayed (hex, rgba, both, etc.)

Any thoughts on this?

@Soviut
Copy link
Author

Soviut commented Aug 30, 2013

I was able to get a simple pass through function working but ran into issues with the function not having access to debugInfo in order to get its line number. Additionally, the function is limited by only being able to be used in an expression.

As such, I have decided to try introducing an @trace directive that can allow variables and expressions to be debugged.

 @value: 10px;

@trace @value;

@trace (@value + 5px);

a {
    @color: blue;
    @trace @color;
}

@seven-phases-max
Copy link
Member

Btw., if you have debug function that works in expressions, trace can simply be defined as a mixin:

.trace(@values...) {@unused_: debug(@values)}

or even:

.trace(@values...) when (debug(@values)) {}

Though I'm not sure if it fits if you need to log specific statement line.

@matthew-dean
Copy link
Member

@seven-phases-max It might work if you altered the trace do pass in a line number, which you would know from the editor.

I'm not sure of the value of this natively. It really has nothing to do with style pre-processing. I think the responsibility lies with Less editing platforms to provide you with debugging tools.

@matthew-dean
Copy link
Member

This is dependent on the root functions PR, but this should be trivial to do as a plugin once that work is completed.

@stale
Copy link

stale bot commented Nov 14, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 14, 2017
@stale stale bot closed this as completed Nov 28, 2017
@ivanbrykov
Copy link

ivanbrykov commented Feb 26, 2021

What's the status here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants