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

Logger option not working if passed through sass-loader #1533

Closed
WIStudent opened this issue Oct 14, 2021 · 6 comments · Fixed by #1538
Closed

Logger option not working if passed through sass-loader #1533

WIStudent opened this issue Oct 14, 2021 · 6 comments · Fixed by #1538
Assignees

Comments

@WIStudent
Copy link

WIStudent commented Oct 14, 2021

I tried silencing messages by passing the new logger option through webpack sass-loader to sass, but they are still being printed.

{
  sassOptions: {
    logger: {
      silent: true
    }
  }
}

I debugged into the sass-loader, and the logger option is passed together with a file and data field to sass' async render function. I think the logger option is not working because it is not passed to the compileStringAsync function inside the render function.
https://github.com/sass/dart-sass/blob/9678e1ae5214b41778b7c04babc4b6c9d33a7269/lib/src/node/legacy.dart#L67-88

I am using sass 1.43.2 and sass-loader 12.2.0.

@alexander-akait
Copy link

@nex3 Found the same problem when I try to implement own logger for sass-loader

@nex3
Copy link
Contributor

nex3 commented Oct 21, 2021

@WIStudent I'm not sure where you got that logger: {silent: true} syntax, but that's not accurate. I think you're looking for logger: Logger.silent.

@alexander-akait Can you provide a minimal reproduction? This works for me locally:

const sass = require('sass');

const result = sass.renderSync({
  data: '@warn "oh heck"',
  logger: {warn: console.log}
});

@alexander-akait
Copy link

@nex3 the main problem when I pass the logger option, dart-sass starts to use 2 loggers - my and own stderr

@WIStudent
Copy link
Author

WIStudent commented Oct 21, 2021

@nex3 I misunderstood this part of the documentation:

By default, Sass emits warnings and debug messages to standard error, but if Logger.warn or Logger.debug is set, this will invoke them instead.

The special value Logger.silent can be used to easily silence all messages.

I saw the examples for debug and warn and assumed that silent is a property like debug/warn.

I wanted to try again using logger: Logger.silent but I could not figure out how to get the Logger object. An example in the documentation would be helpful.

Anyway, for now I can also achieve silence by setting the warn and debug functions and not logging anything inside them. But this only works with the renderSync function, not with the render function. Here is an example:

const sass = require('sass');

// This passes the warning to the custom warn function
sass.renderSync({
  data: '@warn "oh heck"',
  logger: {
    warn(message) {
      console.log('My logger:', message);
    }
  }
});

// This does not pass the warnings to the custom warn function. Instead sass default logging is used.
sass.render({
  data: '@warn "oh heck"',
  logger: {
    warn(message) {
      console.log('My logger:', message);
    }
  }
}, () => {})

@andrew-luminal
Copy link

Echoing @WIStudent, where do we get Logger from? Unless I'm missing something it's not part of the exports.

@nex3
Copy link
Contributor

nex3 commented Oct 21, 2021

Sorry, I didn't realize that the error was specifically with render(), and not with renderSync(). I'll have a PR out to fix that shortly.

The Logger.silent value is documented here, which is linked from LegacySharedOptions.logger. I'll update it with a usage example.

nex3 added a commit to sass/sass-spec that referenced this issue Oct 21, 2021
nex3 added a commit that referenced this issue Oct 21, 2021
nex3 added a commit to sass/sass that referenced this issue Oct 21, 2021
nex3 added a commit that referenced this issue Oct 22, 2021
nex3 added a commit to sass/sass that referenced this issue Oct 26, 2021
nex3 added a commit to sass/sass-spec that referenced this issue Oct 26, 2021
nex3 added a commit that referenced this issue Oct 26, 2021
mirisuzanne pushed a commit to sass/sass that referenced this issue Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants