You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Chris Anderson <jc...@grabb.it> on 2008/05/25 01:31:33 UTC

logging from views

I've been playing with views, and finding the new Reduce a little confusing.

To get a better idea about what's happening I added a log() function
to the view context, that prints to couchjs stderr (which I redirect
to a log file).

Here's the diff: http://pastie.caboo.se/202877

I don't think CouchDB cares about view server stderr, so it seems
handy to make it available to view functions for debugging. The only
thing I'm not sure of is couchjs.tpl.in - maybe there's a better way
to redirect stderr. Also, I don't know which template variable
corresponds to the log directory, so it's still hardcoded.

I want to polish this and road test it before I add it to JIRA, any
feedback will be appreciated!

Chris

-- 
Chris Anderson
http://jchris.mfdz.com

Re: logging from views

Posted by Chris Anderson <jc...@grabb.it>.
On Sun, May 25, 2008 at 6:37 AM, Christopher Lenz <cm...@gmx.de> wrote:
> There's already a simple (but incomplete) provision for logging from the
> view server: you print a JSON-encoded line such as the following to stdout:
>
>  {"log": "bla bla"}
>
> CouchDB will take that and write it to its own log output (at INFO level).
>
> The Javascript view server (share/server/main.js) uses this to log error
> messages. We could simply make this functionality available through a
> `log(message)` function that would be made available inside views.
>

I tried adding a simple function to main.js:

log = function(message) {
  print(toJSON({log: toJSON(message)}));
}

Assigning anything other than a string to the value of "log" was
throwing errors in CouchDB, but wrapping the message in toJSON() gives
the expected results in the couch.log. Thanks for the hint, Chris.

I'll post the complete patch to JIRA.

-- 
Chris Anderson
http://jchris.mfdz.com

Re: logging from views

Posted by Christopher Lenz <cm...@gmx.de>.
On 25.05.2008, at 15:05, Noah Slater wrote:
> On Sat, May 24, 2008 at 04:31:33PM -0700, Chris Anderson wrote:
>> The only thing I'm not sure of is couchjs.tpl.in
>
> Yes, I'm not happy with that as it stands.
>
> Perhaps if this was to go forward I could add a "-l" option to  
> specify a log
> file to write out STDERR. You could then specify this option in the  
> INI file.
>
> I don't know if this would work with the way Erlang invokes couchjs.
>
> Chris, what do you think?

There's already a simple (but incomplete) provision for logging from  
the view server: you print a JSON-encoded line such as the following  
to stdout:

   {"log": "bla bla"}

CouchDB will take that and write it to its own log output (at INFO  
level).

The Javascript view server (share/server/main.js) uses this to log  
error messages. We could simply make this functionality available  
through a `log(message)` function that would be made available inside  
views.

Cheers,
--
Christopher Lenz
   cmlenz at gmx.de
   http://www.cmlenz.net/


Re: logging from views

Posted by Noah Slater <ns...@apache.org>.
On Sat, May 24, 2008 at 04:31:33PM -0700, Chris Anderson wrote:
> The only thing I'm not sure of is couchjs.tpl.in

Yes, I'm not happy with that as it stands.

Perhaps if this was to go forward I could add a "-l" option to specify a log
file to write out STDERR. You could then specify this option in the INI file.

I don't know if this would work with the way Erlang invokes couchjs.

Chris, what do you think?

-- 
Noah Slater - The Apache Software Foundation <http://www.apache.org/>