Writing Debug Messages to the Javascript Console

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ion

    Writing Debug Messages to the Javascript Console

    Hi!
    Is there a way to write messages to the javascript console? Like a
    debug.write() method?
    Thanks!
    Ion

  • Nathan

    #2
    Re: Writing Debug Messages to the Javascript Console

    if you're talking about the Mozilla/Firefox javascript console, there's
    a pretty good wiki document over at mozillazine:



    looks like the easiest way is to do it like this:

    consoleService. logStringMessag e("Hello world!");
    [color=blue]
    > Is there a way to write messages to the javascript console?[/color]

    Comment

    • ion

      #3
      Re: Writing Debug Messages to the Javascript Console

      Nathan,
      Thanks. I couldn't get that to work. I get
      Permission denied to get property UnnamedClass.cl asses
      I think that service is intended for XUL applications. Is there no
      way to write to it with JavaScript? There's a filter for 'messages
      only' in the JavaScript Console itself, so it seems to want to be
      written to.
      Ion

      Comment

      • ion

        #4
        Re: Writing Debug Messages to the Javascript Console

        OK, Neil provides the answer in

        var message = "Hello, world!";
        setTimeout(mess age, 0);

        since "Hello, world!" isn't resolvable as a method call, this gets
        logged as an error [I get 'Missing ; before statement', but it would
        probably be different for a single word message.]

        Comment

        • Hallvord R. M. Steen

          #5
          Re: Writing Debug Messages to the Javascript Console

          On Thu, 07 Apr 2005 20:02:37 +0200, ion <ionFreeman@gma il.com> wrote:
          [color=blue]
          > Is there a way to write messages to the javascript console? Like a
          > debug.write() method?[/color]

          You got an answer for Mozilla already :-)

          If you debug your script in Opera you can use

          opera.postError ();

          :-)

          Comment

          • caston

            #6
            Re: Writing Debug Messages to the Javascript Console


            ion wrote:[color=blue]
            > Hi!
            > Is there a way to write messages to the javascript console? Like a
            > debug.write() method?
            > Thanks!
            > Ion[/color]

            The best way to write to debug console is the follwoing:

            throw new Error("An error occured bla-bla...")

            Note, that using this construction will cause an error alert in IE
            browser, and will write to javascript console in Mozilla-based
            browsers.
            In both cases the script flow will be interrupted after the error
            arisen.

            Comment

            • ion

              #7
              Re: Writing Debug Messages to the Javascript Console

              caston,
              Thanks! I don't want to leave the method body, is why I'm not
              throwing errors.
              Ion

              Comment

              • ion

                #8
                Re: Writing Debug Messages to the Javascript Console

                Dude! Opera rules! It's unfortunately not a supported platform for my
                application. Tough to make the business case.
                Thanks for your help!

                Comment

                • Thomas 'PointedEars' Lahn

                  #9
                  Re: Writing Debug Messages to the Javascript Console

                  ion wrote:
                  [color=blue]
                  > Thanks! I don't want to leave the method body, is why I'm not
                  > throwing errors.[/color]

                  Theoretically, you could re-catch the exception thrown, see
                  the JavaScript 1.5 Guide and/or Reference for details.

                  <http://web.archive.org/devedge.netscap e.com/central/javascript/>


                  PointedEars

                  Comment

                  • ion

                    #10
                    Re: Writing Debug Messages to the Javascript Console

                    Thomas,
                    Thanks! If I caught the errors, they wouldn't be logged. The funny
                    thing about the 1.5 Guide's discussion of exception handling is that
                    they put a function 'logMyErrors' in the catch block, without giving an
                    implementation. All I want to do, of course, is log errors, so there
                    you are.
                    setTimeout is working great for me.
                    Ion
                    Thomas 'PointedEars' Lahn wrote:[color=blue]
                    > ion wrote:
                    >[color=green]
                    > > Thanks! I don't want to leave the method body, is why I'm not
                    > > throwing errors.[/color]
                    >
                    > Theoretically, you could re-catch the exception thrown, see
                    > the JavaScript 1.5 Guide and/or Reference for details.
                    >
                    > <http://web.archive.org/devedge.netscap e.com/central/javascript/>
                    >
                    >
                    > PointedEars[/color]

                    Comment

                    • ion

                      #11
                      Re: Writing Debug Messages to the Javascript Console

                      Thomas,
                      Thanks! If I caught the errors, they wouldn't be logged. The funny
                      thing about the 1.5 Guide's discussion of exception handling is that
                      they put a function 'logMyErrors' in the catch block, without giving an
                      implementation. All I want to do, of course, is log messages, so there
                      you are.
                      setTimeout is working great for me.
                      Ion
                      Thomas 'PointedEars' Lahn wrote:[color=blue]
                      > ion wrote:
                      >[color=green]
                      > > Thanks! I don't want to leave the method body, is why I'm not
                      > > throwing errors.[/color]
                      >
                      > Theoretically, you could re-catch the exception thrown, see
                      > the JavaScript 1.5 Guide and/or Reference for details.
                      >
                      > <http://web.archive.org/devedge.netscap e.com/central/javascript/>
                      >
                      >
                      > PointedEars[/color]

                      Comment

                      Working...