Log inside reduce function


#1

Hi all,

I’m writing a custom reduce function and I need to debug its behaviour.
Can I use console.log (or any log function) inside the reduce code?

Thanks,

Giovanni


#2

Hi,
you can use the log function:

 function (doc, meta) {
   log("indexing " + doc.type);
   emit(meta.id, null);     
 }

Results are availeble in the mapreduce_errors.log file.


#3

Thanks Idoguin,

the example you reported is for a map function, but I need ti debug the reduce function. I tried the following code:

function(keys, values, rereduce) {
  log("debug in reduce function");
  return values[0];
}

and in the mapreduce_errors.log file I get the following message:

failed to execute HTTP request, Success: error: Reducer: Error building index for view `by_device_and_data_type`, reason: ReferenceError: log is not defined (Not an error)

Thanks,

Giovanni


#4

Ah, sorry about that. I did not test the reduce. It seems you can only log stuff inside the map function.