question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filter out stdout/stderr messages

See original GitHub issue

Clear and concise description of the problem

I’m working on a LitHtml project and when you run it in development mode it logs a message to the console, that appears when I do test runs:

stderr | unknown test
Lit is in dev mode. Not recommended for production!
 See https://lit.dev/msg/dev-mode for more informat
ion.

When running my tests, I get this multiple times and it provides no value. I know I can use --silent to ignore all output, but I do want to see any other messages.

Suggested solution

I was picturing a configuration setting that you could set:

{
  ignoreConsoleMessages: {
    source: 'stderr' // 'stdout' | 'stderr'
    match: /Lit is in dev mode/
  }
}

Or similar. That way the developer can very explicitly ignore certain messages, but can still see all other messages.

If this is acceptable, I would be happy to make an attempt at implementation in a PR 👍

Alternative

I think I could solve this in user-land by using a stubbing library such as sinon, and mock the console methods. But I think this is something worth considering solving in the configuration layer.

Additional context

No response

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
BenSheltoncommented, Dec 15, 2022

It appears you can now also do this with a (currently undocumented) option in your vite/vitest config:

test: {
  onConsoleLog (log) {
    if (log.includes('Download the Vue Devtools extension')) return false
    if (log.includes('Lit is in dev mode.')) return false
  },
2reactions
treardon17commented, Aug 22, 2022

@nicooprat I had the same issue as you – not being able to disable the productionTip/devtools logging. After messing with the config for a bit, I was able to finally disable the logs by creating a vitest.setup.js containing this:

import { vi } from 'vitest';

vi.mock('vue', async () => {
  const Vue = await vi.importActual('vue') as any;

  Vue.default.config.productionTip = false;
  Vue.default.config.devtools = false;

  return Vue;
});

and then adding this to my vitest.config.js:

{
  test: {
    setupFiles: [
      path.resolve(__dirname, './vitest.setup.js'),
    ],
  },
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pipe only STDERR through a filter - linux - Stack Overflow
First save stdout as &3 (&1 is duped into 3) · Next send stdout to stderr (&2 is duped into 1) · Send...
Read more >
Piping STDERR to STDOUT for filtering, done right - BurgerBum
Let's use this to filter tar. The archiving program tar produces a lot of error messages on STDERR, some of which are important...
Read more >
Filtering Only the Standard Error in Linux - Baeldung
Another way to filter only the standard error is to swap the file descriptors. We can interchange the standard output and standard error, ......
Read more >
Filter stdout and stderr Together
Hi All, I would like to write a script that filters lines from both stdout and stderr, and output the lines in the...
Read more >
How to filter error messages in real time - Unix Stack Exchange
My goal is to filter out these messages while still printing any other error messages (and of course normal stdout) in real time....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found