Console logging stopped working in SG 2.5

I upgraded from SG 2.1 to 2.5. console.log("my log") logs in the SG fn were appended to sync_gateway_access.log in SG 2.1. This stopped working in SG 2.5. The config for logs is:

{
  "logging": {
    "log_file_path": "/home/sync_gateway/logs",
    "console": {
      "log_level": "debug",
      "log_keys": [
        "*"
      ],
      "color_enabled": true
    },
    "error": {
      "enabled": true,
      "rotation": {
        "max_size": 100,
        "max_age": 360,
        "localtime": false
      }
    },
    "warn": {
      "enabled": true,
      "rotation": {
        "max_size": 100,
        "max_age": 180,
        "localtime": false
      }
    },
    "info": {
      "enabled": true,
      "rotation": {
        "max_size": 100,
        "max_age": 6,
        "localtime": false
      }
    },
    "debug": {
      "enabled": true,
      "rotation": {
        "max_size": 100,
        "max_age": 2,
        "localtime": false
      }
    }
  }
}

Despite having debug and * I cannot find the logs in either of these files:

  • sg_debug.log
  • sg_info.log
  • sg_warn.log
  • sg_error.log
  • sync_gateway_access.log
  • sync_gateway_error.log

Where should I look, or what needs to be changed to show them again?

Thanks!

Hi @benjamin_glatzeder,

In 2.5.x Sync Gateway’s sync function logging will be printed to the console only. Depending on what OS you’re running, and how you start Sync Gateway, this could end up in systemd’s logs, Docker’s logs, etc. It used to be that console logging was piped into the sync_gateway_error.log file, but was superceeded by the sg_*.log files.

We fixed this in 2.6.0 so that sync function logging is fully integrated with the sg_info.log, sg_error.log files for console.log() and console.error().

1 Like

I can confirm that in SG 2.6 console.log() prints to sg_info.log and console.error() prints to sg_error.log.

I read in another post about sglog. Is this a new public logging function which can be used by developers? In any case console.log() is good for debugging/testing.

sglog was originally proposed as a workaround, but we decided to override the default console.log and console.error behaviour, as it’s more likely to be used by developers already familiar with Javascript, so stay with using those! Glad to hear it works OK for you.