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

Consider changing console.debug to console.log #72

Closed
andrewferrier opened this issue Nov 26, 2023 · 12 comments
Closed

Consider changing console.debug to console.log #72

andrewferrier opened this issue Nov 26, 2023 · 12 comments

Comments

@andrewferrier
Copy link
Owner

https://www.reddit.com/r/neovim/comments/1848aoc/comment/kaw948m/?utm_source=share&utm_medium=web2x&context=3

@andrewferrier
Copy link
Owner Author

This has been done: c8341fd.

@CarlosMed
Copy link

CarlosMed commented Jan 17, 2024

I know you had set this to console.warn but this sometimes muddies the console as seen In the pic. If you default to console.log, it should suffice for everything under the JS umbrella.

image

vs

image

@andrewferrier
Copy link
Owner Author

@CarlosMed hmm, this is a tricky one. JavaScript is not just used in browsers, but in NodeJS and other runtimes too, so I'm cautious about optimising for the browser use case by creating an exception from the usual principle of making DEBUGPRINT stand out, common though it might be. Is that the default behaviour of your browser?

@andrewferrier andrewferrier reopened this Jan 17, 2024
@CarlosMed
Copy link

CarlosMed commented Jan 17, 2024

As far as I know, NodeJS also has a console.log as well as DenoJS and BunJS. On the above with console.warn it throws in way too much info that's unnecessary. The only way I guess to appease people would be to make the console more agnostic where It can be changed in the config from log or warn.

@andrewferrier
Copy link
Owner Author

@CarlosMed so I've done some testing of console.log(), console.warn(), console.debug() and console.error():

  • On NodeJS, they all display the same by default, except that warn and error go to stderr (which I consider desirable, albeit not essential, following the principles here.

  • On Firefox (Librewolf 121.0 to be precise), it displays log and debug in plain text, with warn in yellow text, and error in red text. None of the logging lines are 'expanded' in the way you show.

  • On Chrome (121), it displays 'log', 'warn', and 'error' by default, with warn in yellow and error in red by default. Again, all of the logging lines are just single lines and not 'expanded'.

I can't recreate what you are showing in your screenshots. My guess would be (I don't do much browser JavaScript) that you are logging an variable/object with a stacktrace called 'error', in which case it makes sense (I think) that it's expanded.

So I'm unclear what issue you're referring to when you say 'way too much info' - from my testing it seems like it's the same level of info whichever console method you use. Can you provide some more specific recreation instructions?

Of course, remember you can always override the behaviour in any event in your own config as described here. If you specify an existing filetype, it will override the behaviour for that filetype.

@CarlosMed
Copy link

The above solved my issue. Since it makes it flexible. Thank you!

@andrewferrier
Copy link
Owner Author

OK, thanks. I'm closing this issue since I can't recreate the specific problem you described and it sounds like you've fixed with changes to your own config. Thanks for your contribution!

@tolluset
Copy link

For those who followed by console.warn issuse, if you use javascript and typescript (and react) maybe you should set whole languages like below.

I'm changed console.warn -> console.info by this setting. (in lazyvim)

 return {
  {
    "andrewferrier/debugprint.nvim",
    config = function()
      require("debugprint").setup({
        filetypes = {
          ["js"] = {
            left = 'console.info("',
            right = '")',
            mid_var = '", ',
            right_var = ")",
          },

          ["javascript"] = {
            left = 'console.info("',
            right = '")',
            mid_var = '", ',
            right_var = ")",
          },

          ["javascriptreact"] = {
            left = 'console.info("',
            right = '")',
            mid_var = '", ',
            right_var = ")",
          },

          ["typescript"] = {
            left = 'console.info("',
            right = '")',
            mid_var = '", ',
            right_var = ")",
          },

          ["typescriptreact"] = {
            left = 'console.info("',
            right = '")',
            mid_var = '", ',
            right_var = ")",
          },
        },
      })
    end,
    version = "*",
  },
}

@andrewferrier
Copy link
Owner Author

Thanks @tolluset! I'll keep the default will stay at console.warn() for now, given the investigation above, unless someone can give a compelling reason otherwise, but I am considering creating a semi-official 'showcase' of alternative debugprint setups, and I might adapt something like this into that showcase. Thanks for the heads-up.

By the way, you can do this a bit more efficiently like this:

 local js_like = {
   left = 'console.info("',
   right = '")',
   mid_var = '", ',
   right_var = ")",
 }

 return {
  {
    "andrewferrier/debugprint.nvim",
    config = function()
      require("debugprint").setup({
        filetypes = {
          ["javascript"] = js_like,
          ["javascriptreact"] = js_like,
          ["typescript"] = js_like,
          ["typescriptreact"] = js_like,
        },
      })
    end,
    version = "*",
  },
}

@andrewferrier
Copy link
Owner Author

Oh, and just a heads-up @tolluset - js isn't a valid filetype in NeoVim, I believe - it's javascript.

@tolluset
Copy link

Thanks @tolluset! I'll keep the default will stay at console.warn() for now, given the investigation above, unless someone can give a compelling reason otherwise, but I am considering creating a semi-official 'showcase' of alternative debugprint setups, and I might adapt something like this into that showcase. Thanks for the heads-up.

By the way, you can do this a bit more efficiently like this:

 local js_like = {
   left = 'console.info("',
   right = '")',
   mid_var = '", ',
   right_var = ")",
 }

 return {
  {
    "andrewferrier/debugprint.nvim",
    config = function()
      require("debugprint").setup({
        filetypes = {
          ["javascript"] = js_like,
          ["javascriptreact"] = js_like,
          ["typescript"] = js_like,
          ["typescriptreact"] = js_like,
        },
      })
    end,
    version = "*",
  },
}

This way looks great!! Thanks!!! ☺️

@andrewferrier
Copy link
Owner Author

This way looks great!! Thanks!!! ☺️

FYI - I'm now starting to track configurations such as this in a showcase.

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

No branches or pull requests

3 participants