+10 global
+9 module
Christoph
Sure. Can you write it up? I'm pretty sure it needs to be a module;
not another free-var. We might want to pick and chose which parts
should be feature-tested before use.
Kris Kowal
I think console.log() can replace print() and I would rather have
"console" as a free variable than "print".
Being able to get debug messages with nicer formatting to a place where
you can view them is essential for newcomers I think. Each engine can
provide a console implementation that directs messages to the
appropriate destination and formats logged objects such as Errors by
attaching stack traces etc...
I use Firebug's console API when working with narwhal on xulrunner and
it is real nice to be able to inspect objects and not just see printed
strings. I envision debuggers connected to the console API that can
inspect object graphs even on server-side programs.
Christoph
--
You received this message because you are subscribed to the Google Groups "CommonJS" group.
To post to this group, send email to comm...@googlegroups.com.
To unsubscribe from this group, send email to commonjs+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/commonjs?hl=en.
Why not have both a full featured logging API and a console log
(whatever it's called), with the console simply being an easily
available default instance of a logger? In ringojs we have a fully
featured logging system[1][2], but instantiating a logger by name
(usually require('ringo/logging).getLogger(module.id)) is often too
cumbersome, so I just end up using print(). Having a predefined logger
instance in the console or system module would definitely help.
The Firebug console API seems like a good place to start. It's
slightly extensive, so I think we might want to trim off some less
essential features. One difference to our API is we just use {} as
format string placeholder instead of typed placeholders like %s or %n.
I like this very much, and I don't think these typed placeholders make
a lot of sense in JS.
[1] http://ringojs.org/api/ringo/logging
[2] http://ringojs.org/demo/logging
hannes
I also think that we are talking about two modules:
1) system.print()
Which is already ratified afaik.
2) console
Containing at least console.log, which MAY be a wrapper on
system.print() or MAY be vice verse.
Although it is true that not all platforms have a "console", most
browsers have some notion of a console, making this feature a nice
convenience that we can rely on.
I use CommonJS on the server, Narwhal for general purpose programming,
and CommonJS in the browser. While system.print() is right for most
of these use cases, it does not seem appropriate for the browser.
I think I would be fine with having separate standards that give us
require("system").print, require("console").*, and
require("logging").Logger().* in lieu of free variables, leaving
implementations free to hook these up in whatever way makes sense in
the embedding. I talked myself out of having a "system" free
variable. I don't want to talk myself out of a "print" free variable
that forwards to require("system").print and then
require("system").stdout.print, but I can. My reasoning for having
"print" free is just for pedagogy; when I, say, end up teaching
Computer Merit Badge to some 11-year-old, I want the first lesson to
be:
print("Hello, World!");
Having to import a module on the first lesson can be a bit of a
buzz-kill. Other than that, I can deal with having to import "system"
if I want to print stuff. I also think it make sense for print to
write to the console in browsers by default. I don't think that
replaces the functionality of "console", and it would be useful to
have a "console" module on the server-side, and I don't think that the
server-side analog of the "console" is the same thing as the root
serial console, although there are some similarities in intent: an
output space, hidden from the user.
As for the status of these proposals:
* The System/1.0 version does not contain "print". There is a
proposal to amend it, but we have not asked for a show of hands.
* We need the requirements for a Console/A proposal on our wiki for
review. Someone needs to take responsibility for this discussion and
do the wiki-wrangling.
Thanks,
Kris Kowal
A console API spec is nicely timed. I've been working on some new server-side stuff and dragged over an old Logger class to ease some debugging and bench marking. I re-named it console though as that is now how my mind is wired up and that of my work mates and to a large extent the javascript community as a whole. I see nothing wrong with the concept of a console being a bucket for debugging messages what ever it maybe on each system or however that maybe be implemented (Firebug, HTML in a DIV, textfile, flashing lights on a patch panel?)There is alot of mileage in using the conventions already around to ease entry into using JS full on.
- Chrome doesn't have groupCollapsed() or assert(), Safari doesn't
have groupCollapsed(), so I think it might make sense to leave those
out, if our goal is to mirror things you can safely do in a browser.
- I wonder what we might expect of the profile*(), time*() and dir*()
methods. Can we expect all server implementations to do sane things
with those? It could be useful to have them there and be no-ops, if
browser environment compliance is important.
Joe.
On Mar 20, 9:17 pm, Irakli Gozalishvili <rfo...@gmail.com> wrote:
> I wrote up a proposal for a [console module](http://wiki.commonjs.org/wiki/Console) hopefully I managed to take into
> account all the comments in this thread. Most of it intentionally matches
> Firebug's Console API.
>
> Hope it's a good starting point.
>
> Regarding `print`. What about system 1.1 with added print to it.
>
> I think weather or not print / global / system should be a free variables is
> whole different topic and should live in separate thread.
>
> Regards,
> --
> Irakli Gozalishvili
> Web:http://rfobic.wordpress.com/
> Phone: +31 614 205275
> Address: Taksteeg 3 - 4, 1012PB Amsterdam, Netherlands
>
> > commonjs+u...@googlegroups.com<commonjs%2Bunsu...@googlegroups.com>
To unsubscribe from this group, send email to commonjs+u...@googlegroups.com.
I think this should be pared back to
.log
.debug
.info
.warn
.error
and possibly adding console.critical()
I do not deny that the rest of the console tools in the proposal are
useful, I just think they belong in other modules. Maybe even outside
of the standard modules. As it is, the current console proposal
tightly couples functionality that is only loosely related in
practice.
On the other hand, debug, info, warn, error, and critical are quite
common output abstractions in the industry at large. Some
implementations may do different things with these abstractions, but I
can't think of any platforms that would not be able to represent each
of these log types in some sort of meaningful way.
Also, like Kris Kowal, I would love to see a free print() statement.
However, I don't think it should be allowed into the spec because of
the abominable window.print() in the browsers. Unfortunately.
- Kris
--
You received this message because you are subscribed to the Google Groups "CommonJS" group.
To post to this group, send email to comm...@googlegroups.com.
To unsubscribe from this group, send email to commonjs+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/commonjs?hl=en.
You're right, that is a logging API, but it is a lot less than what is
on the current proposal. In your mind does console just
contain .log(). If so, I've no problem with that either.
My problem is that the proposal is going too far as it is written.
I'm not going to want all that other stuff attached to the console
object. At a MAXIMUM I can see a use for debug, info, warn, err,
critical.
- Kris
As a general rule, compatibility with firebug/safari console object is good. But then i never use much beyond console.log myself. The other debug, warn, err etc make sense - not sure the rest of the stuff does (but that might just be because I didn't know it was there)
-ash
--
I see the point that Irakli is making that limiting the console API
will create a gap between CommonJS and current mainstream use of the
console API. However, I believe that the console is simply an output
at the end of the day. It is an output that could be used for
debugging, error reporting, logging and maybe other yet to be
discovered use cases. If the API is allowed to expand too far, future
extensibility is limited.
The current CommonJS console proposal looks more like a third party
library or module to fulfill a wish list.
These extra features can, and should be, provided by third party
modules that may overload the console object however they see fit.
--
There doesn't appear to be a great deal of contention, so moving
forward with this probably doesn't require a show of hands. Let's get
some implementations and a compliance test suite. I don't intend to
implement this specification myself, but if someone wants to
contribute one, I think that would be great. When there are three
compliant implementations, it's probably as good as ratified.
Kris Kowal
In Wakanda we implemented log, debug, info, warn, error, assert, and
we considered a "fatal" method because it is one of the terms used in
log4j (which is a format supported by interesting tools)
http://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/log4j/log4j.html
We also considered added a level property (setLevel, may require to
add a getLevel) and some constants so you can write :
// possibly
var console = require("console");
// next log, debug, and info messages won't be output
console.level = console.WARN;
I think log, debug, info, warn, error are must have.
They are the most used feature.
I personally didn't used much group and groupEnd in browsers because
events handlers can easily break them (I'd expect group() to return an
identifier used for groupEnd()). On Server-side it might be less a
problem and could also be used to append the namespace in the log
format.
We also thought about a target property with another st of constants
(understand readonly properties, thanx ES5 it's even easier now)
Other methods are interesting and we may add it later
On Mar 23, 2:46 pm, Kris Walker <kixxa...@gmail.com> wrote:
> The console proposal is doing WAY too much IMO.http://wiki.commonjs.org/wiki/Console
On Apr 2, 12:13 am, Irakli Gozalishvili <rfo...@gmail.com> wrote:
> I've send a pull request
>
> http://github.com/Gozala/narwhal/commit/abd96e4889594750516af7c70f910...
>
I understand your point, but since the console object will not be a
free variable, it's name doesn't need to be "console".
Un-modularized code will need to be adapted anyways, and can restore
the console variable.
var console = require("logger");
My two cents on this proposal:
1. I agree with others that perhaps using printf-style token
references (e.g. %s) is not necessary in a language where type
coercion exists. In whatever logging implementations I've done so far,
I've been quite comfortable with using Perl-style tokens. I use
{property_name} and {array_index} support simultaneously:
// Use an object's properties
console.log("The value of {name} is {value}.", { name: "foo", value: 1 });
// Use argument indices (1-based):
console.log("The value of {1} is {2}.", foo, 1);
// Mix and match!
console.log("The value of {name} is {value} as of {2}.", { name:
"foo", value: 1 }, new Date());
2. I like the idea of group() for automatic indentation / hierarchical
relation of messages. However, I think I would just let it return a
new console instance, that has the indentation/hierarchy ingrained:
console.log("Running test suite " + suite.name);
runSuite(suite, console.group());
function runSuite(suite, console) {
utils.each(suite, function (test, name) {
console.log("Running test " + name);
...
});
}