{
  "schema_version": 2,
  "id": "operate/oss_and_stack/stack-with-enterprise/deprecated-features/triggers-and-functions/Debugging",
  "title": "Debugging",
  "url": "https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/triggers-and-functions/debugging/",
  "summary": "Methods for debugging your Redis Stack functions",
  "aliases": [
    "/develop/interact/programmability/triggers-and-functions/debugging/"
  ],
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-21T16:36:38+01:00",
  "page_type": "content",
  "content_hash": "3b138282e2855c4fd97d9b5428beb3476ca29f328c797037d023459a3f46bf0f",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "There are two methods you can use to debug your Redis Stack functions:\n\n1. Make judicious use of the `redis.log` function, which writes to the Redis log file.\n1. Use Redis [pub/sub](https://redis.io/docs/latest/develop/pubsub)."
    },
    {
      "id": "use-redislog",
      "title": "Use `redis.log`",
      "role": "content",
      "text": "If you have access to the Redis log files, `redis.log` is a good method to use when debugging. However, there is a drawback. Redis Cloud users do not have access to the Redis log files, and it's pretty common that only system administrators have access to them on self-hosted installations. Fortunately, you can also use Redis pub/sub, which will be discussed in the next section.\n\nYou don't have to do anything special to use `redis.log`, as it's always available. Here is an example:\n\n[code example]\n\nAfter loading the library and executing the function with `TFCALL`, you'll see something like the following in your Redis log file:\n\n[code example]"
    },
    {
      "id": "use-redis-pubsub",
      "title": "Use Redis pub/sub",
      "role": "content",
      "text": "If you don't have access to your Redis database log files, you can use pub/sub. The following example demonstrates how to use the [client.call](https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/triggers-and-functions/concepts/JavaScript_API#clientcall) API to publish to a pub/sub channel.\n\n[code example]\nIn a CLI session, subscribe to the `tfLogChannel` channel and watch for messages.\n\n[code example]\n\nIn another CLI session, load the library, replacing what was already there, and then call the new function:\n\n[code example]\n\nYou'll see the following in the previous CLI session:\n\n[code example]\n\nThere is a downside to using pub/sub. Redis pub/sub provides at-most-once message delivery semantics, which means that once a message is sent, it won't be sent again. So, if a message isn't consumed, it's gone forever. This is likely okay for debugging, but for the longer term, `redis.log` is the better solution for log persistence."
    }
  ],
  "examples": [
    {
      "id": "use-redislog-ex0",
      "language": "javascript",
      "code": "#!js api_version=1.0 name=lib\n\nredis.registerFunction('hello', ()=> {\n  redis.log('Hello log')\n  return 'Hello from an external file'\n})",
      "section_id": "use-redislog"
    },
    {
      "id": "use-redislog-ex1",
      "language": "plaintext",
      "code": "45718:M 01 Nov 2023 07:02:40.593 * <redisgears_2> Hello log",
      "section_id": "use-redislog"
    },
    {
      "id": "use-redis-pubsub-ex0",
      "language": "javascript",
      "code": "#!js api_version=1.0 name=lib\n\nconst logChannel = 'tfLogChannel'\n\nfunction publog(client, message) {\n  client.call('publish', logChannel, message)\n}\n\nredis.registerFunction('tflog', (client) => {\n  publog(client, 'sample pub/sub log message')\n  return 'sample'\n})",
      "section_id": "use-redis-pubsub"
    },
    {
      "id": "use-redis-pubsub-ex1",
      "language": "redis",
      "code": "$ redis-cli\n127.0.0.1:6379> subscribe tfLogChannel\n1) \"subscribe\"\n2) \"tfLogChannel\"\n3) (integer) 1\nReading messages... (press Ctrl-C to quit or any key to type command)",
      "section_id": "use-redis-pubsub"
    },
    {
      "id": "use-redis-pubsub-ex2",
      "language": "redis",
      "code": "127.0.0.1:6379> TFCALL lib.tflog 0\n\"sample\"",
      "section_id": "use-redis-pubsub"
    },
    {
      "id": "use-redis-pubsub-ex3",
      "language": "redis",
      "code": "1) \"message\"\n2) \"tfLogChannel\"\n3) \"sample pub/sub log message\"",
      "section_id": "use-redis-pubsub"
    }
  ]
}
