Log inside reduce function

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?



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.

1 Like

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)



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