{"id":13483392,"url":"https://github.com/fluent/fluent-logger-node","last_synced_at":"2025-05-16T11:04:44.518Z","repository":{"id":6253034,"uuid":"7485567","full_name":"fluent/fluent-logger-node","owner":"fluent","description":"A structured logger for Fluentd (Node.js)","archived":false,"fork":false,"pushed_at":"2021-07-27T11:24:34.000Z","size":351,"stargazers_count":260,"open_issues_count":23,"forks_count":84,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-05-12T17:22:04.421Z","etag":null,"topics":["fluentd","fluentd-logger","node-js"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fluent.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-07T16:22:38.000Z","updated_at":"2025-01-04T00:32:48.000Z","dependencies_parsed_at":"2022-08-06T19:15:24.742Z","dependency_job_id":null,"html_url":"https://github.com/fluent/fluent-logger-node","commit_stats":null,"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Ffluent-logger-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Ffluent-logger-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Ffluent-logger-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Ffluent-logger-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fluent","download_url":"https://codeload.github.com/fluent/fluent-logger-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254518384,"owners_count":22084374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fluentd","fluentd-logger","node-js"],"created_at":"2024-07-31T17:01:10.722Z","updated_at":"2025-05-16T11:04:39.503Z","avatar_url":"https://github.com/fluent.png","language":"JavaScript","readme":"# fluent-logger for Node.js\n\nfluent-logger implementation for Node.js inspired by [fluent-logger-python].\n\n[![NPM](https://nodei.co/npm/fluent-logger.png?downloads=true\u0026downloadRank=true)](https://nodei.co/npm/fluent-logger/)\n\n[![Build Status](https://secure.travis-ci.org/fluent/fluent-logger-node.png?branch=master,develop)](http://travis-ci.org/fluent/fluent-logger-node)\n\n## Install\n\n    $ npm install fluent-logger\n\n## Prerequistes\n\nFluent daemon should listen on TCP port.\n\nSimple configuration is following:\n\n```aconf\n\u003csource\u003e\n  @type forward\n  port 24224\n\u003c/source\u003e\n\n\u003cmatch **.*\u003e\n  @type stdout\n\u003c/match\u003e\n```\n\n## Usage\n\n### Send an event record to Fluentd\n\nSingleton style\n\n```js\nvar logger = require('fluent-logger')\n// The 2nd argument can be omitted. Here is a default value for options.\nlogger.configure('tag_prefix', {\n   host: 'localhost',\n   port: 24224,\n   timeout: 3.0,\n   reconnectInterval: 600000 // 10 minutes\n});\n\n// send an event record with 'tag.label'\nlogger.emit('label', {record: 'this is a log'});\n```\n\nInstance style\n\n```js\nvar logger = require('fluent-logger').createFluentSender('tag_prefix', {\n   host: 'localhost',\n   port: 24224,\n   timeout: 3.0,\n   reconnectInterval: 600000 // 10 minutes\n});\n```\n\nThe emit method has following signature\n\n```js\n.emit([label string], \u003crecord object\u003e, [timestamp number/date], [callback function])\n```\n\nWhere only the `record` argument is required. If the label is set it will be\nappended to the configured tag.\n\n### Disable automatic reconnect \nBoth Singleton and Instance style can disable automatic reconnect allowing the user to handle reconnect himself\n```js\nlogger.configure('tag_prefix', {\n   host: 'localhost',\n   port: 24224,\n   timeout: 3.0,\n   enableReconnect: false // defaults to true\n});\n```\n\n### Shared key authentication\n\nLogger configuration:\n\n```js\nvar logger = require('fluent-logger').createFluentSender('dummy', {\n  host: 'localhost',\n  port: 24224,\n  timeout: 3.0,\n  reconnectInterval: 600000, // 10 minutes\n  security: {\n    clientHostname: \"client.localdomain\",\n    sharedKey: \"secure_communication_is_awesome\"\n  }\n});\nlogger.emit('debug', { message: 'This is a message' });\n```\n\nServer configuration:\n\n```aconf\n\u003csource\u003e\n  @type forward\n  port 24224\n  \u003csecurity\u003e\n    self_hostname input.testing.local\n    shared_key secure_communication_is_awesome\n  \u003c/security\u003e\n\u003c/source\u003e\n\n\u003cmatch dummy.*\u003e\n  @type stdout\n\u003c/match\u003e\n```\n\nSee also [Fluentd](https://github.com/fluent/fluentd) examples.\n\n### TLS/SSL encryption\n\nLogger configuration:\n\n```js\nvar logger = require('fluent-logger').createFluentSender('dummy', {\n  host: 'localhost',\n  port: 24224,\n  timeout: 3.0,\n  reconnectInterval: 600000, // 10 minutes\n  security: {\n    clientHostname: \"client.localdomain\",\n    sharedKey: \"secure_communication_is_awesome\"\n  },\n  tls: true,\n  tlsOptions: {\n    ca: fs.readFileSync('/path/to/ca_cert.pem')\n  }\n});\nlogger.emit('debug', { message: 'This is a message' });\n```\n\nServer configuration:\n\n```aconf\n\u003csource\u003e\n  @type forward\n  port 24224\n  \u003ctransport tls\u003e\n    ca_cert_path /path/to/ca_cert.pem\n    ca_private_key_path /path/to/ca_key.pem\n    ca_private_key_passphrase very_secret_passphrase\n  \u003c/transport\u003e\n  \u003csecurity\u003e\n    self_hostname input.testing.local\n    shared_key secure_communication_is_awesome\n  \u003c/security\u003e\n\u003c/source\u003e\n\n\u003cmatch dummy.*\u003e\n  @type stdout\n\u003c/match\u003e\n```\n\nFYI: You can generate certificates using fluent-ca-generate command since Fluentd 1.1.0.\n\nSee also [How to enable TLS/SSL encryption](https://docs.fluentd.org/input/forward#how-to-enable-tls-encryption).\n\n### Mutual TLS Authentication\n\nLogger configuration:\n\n```js\nvar logger = require('fluent-logger').createFluentSender('dummy', {\n  host: 'localhost',\n  port: 24224,\n  timeout: 3.0,\n  reconnectInterval: 600000, // 10 minutes\n  security: {\n    clientHostname: \"client.localdomain\",\n    sharedKey: \"secure_communication_is_awesome\"\n  },\n  tls: true,\n  tlsOptions: {\n    ca: fs.readFileSync('/path/to/ca_cert.pem'),\n    cert: fs.readFileSync('/path/to/client-cert.pem'),\n    key: fs.readFileSync('/path/to/client-key.pem'),\n    passphrase: 'very-secret'\n  }\n});\nlogger.emit('debug', { message: 'This is a message' });\n```\n\nServer configuration:\n\n```aconf\n\u003csource\u003e\n  @type forward\n  port 24224\n  \u003ctransport tls\u003e\n    ca_path /path/to/ca-cert.pem\n    cert_path /path/to/server-cert.pem\n    private_key_path /path/to/server-key.pem\n    private_key_passphrase very_secret_passphrase\n    client_cert_auth true\n  \u003c/transport\u003e\n  \u003csecurity\u003e\n    self_hostname input.testing.local\n    shared_key secure_communication_is_awesome\n  \u003c/security\u003e\n\u003c/source\u003e\n\n\u003cmatch dummy.*\u003e\n  @type stdout\n\u003c/match\u003e\n```\n\n### EventTime support\n\nWe can also specify [EventTime](https://github.com/fluent/fluentd/wiki/Forward-Protocol-Specification-v1#eventtime-ext-format) as timestamp.\n\n```js\nvar FluentLogger = require('fluent-logger');\nvar EventTime = FluentLogger.EventTime;\nvar logger = FluentLogger.createFluentSender('tag_prefix', {\nvar eventTime = new EventTime(1489547207, 745003500); // 2017-03-15 12:06:47 +0900\nlogger.emit('tag', { message: 'This is a message' }, eventTime);\n```\n\n### Events\n\n* `connect` : Handle [net.Socket Event: connect](https://nodejs.org/api/net.html#net_event_connect)\n* `error` : Handle [net.Socket Event: error](https://nodejs.org/api/net.html#net_event_error_1)\n\n```js\nvar logger = require('fluent-logger').createFluentSender('tag_prefix', {\n   host: 'localhost',\n   port: 24224,\n   timeout: 3.0,\n   reconnectInterval: 600000 // 10 minutes\n});\nlogger.on('error', (error) =\u003e {\n  console.log(error);\n});\nlogger.on('connect', () =\u003e {\n  console.log('connected!');\n});\n```\n\n## Logging Library Support\n\n### log4js\n\nUse [log4js-fluent-appender](https://www.npmjs.com/package/log4js-fluent-appender).\n\n### winston\n\nBefore using [winston](https://github.com/winstonjs/winston) support, you should install it IN YOUR APPLICATION.\n\n```js\nvar winston = require('winston');\nvar config = {\n  host: 'localhost',\n  port: 24224,\n  timeout: 3.0,\n  requireAckResponse: true // Add this option to wait response from Fluentd certainly\n};\nvar fluentTransport = require('fluent-logger').support.winstonTransport();\nvar fluent = new fluentTransport('mytag', config);\nvar logger = winston.createLogger({\n  transports: [fluent, new (winston.transports.Console)()]\n});\n\nlogger.on('flush', () =\u003e {\n  console.log(\"flush\");\n})\n\nlogger.on('finish', () =\u003e {\n  console.log(\"finish\");\n  fluent.sender.end(\"end\", {}, () =\u003e {})\n});\n\nlogger.log('info', 'this log record is sent to fluent daemon');\nlogger.info('this log record is sent to fluent daemon');\nlogger.info('end of log message');\nlogger.end();\n```\n\n**NOTE** If you use `winston@2`, you can use `fluent-logger@2.7.0` or earlier. If you use `winston@3`, you can use `fluent-logger@2.8` or later.\n\n### stream\n\nSeveral libraries use stream as output.\n\n```js\n'use strict';\nconst Console = require('console').Console;\nvar sender = require('fluent-logger').createFluentSender('tag_prefix', {\n   host: 'localhost',\n   port: 24224,\n   timeout: 3.0,\n   reconnectInterval: 600000 // 10 minutes\n});\nvar logger = new Console(sender.toStream('stdout'), sender.toStream('stderr'));\nlogger.log('this log record is sent to fluent daemon');\nsetTimeout(()=\u003e sender.end(), 5000);\n```\n\n\n## Options\n\n**tag_prefix**\n\nThe tag prefix string.\nYou can specify `null` when you use `FluentSender` directly.\nIn this case, you must specify `label` when you call `emit`.\n\n**host**\n\nThe hostname. Default value = 'localhost'.\n\nSee [socket.connect][1]\n\n**port**\n\nThe port to listen to. Default value = 24224.\n\nSee [socket.connect][1]\n\n**path**\n\nThe path to your Unix Domain Socket.\nIf you set `path` then fluent-logger ignores `host` and `port`.\n\nSee [socket.connect][1]\n\n**timeout**\n\nSet the socket to timetout after `timeout` milliseconds of inactivity\non the socket.\n\nSee [socket.setTimeout][2]\n\n**reconnectInterval**\n\nSet the reconnect interval in milliseconds.\nIf error occurs then reconnect after this interval.\n\n[1]: https://nodejs.org/api/net.html#net_socket_connect_path_connectlistener\n[2]: https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback\n\n**requireAckResponse**\n\nChange the protocol to at-least-once. The logger waits the ack from destination.\n\n**ackResponseTimeout**\n\nThis option is used when requireAckResponse is true. The default is 190. This default value is based on popular `tcp_syn_retries`.\n\n**eventMode**\n\nSet [Event Modes](https://github.com/fluent/fluentd/wiki/Forward-Protocol-Specification-v1#event-modes). This logger supports `Message`, `PackedForward` and `CompressedPackedForward`.\nDefault is `Message`.\n\nNOTE: We will change default to `PackedForward` and drop `Message` in next major release.\n\n**flushInterval**\n\nSet flush interval in milliseconds. This option has no effect in `Message` mode.\nThe logger stores emitted events in buffer and flush events for each interval.\nDefault `100`.\n\n**messageQueueSizeLimit**\n\nMaximum number of messages that can be in queue at the same time. If a new message is received and it overflows the queue then the oldest message will be removed before adding the new item. This option has effect only in `Message` mode. No limit by default.\n\n**security.clientHostname**\n\nSet hostname of this logger. Use this value for hostname based authentication.\n\n**security.sharedKey**\n\nShared key between client and server.\n\n**security.username**\n\nSet username for user based authentication. Default values is empty string.\n\n**security.password**\n\nSet password for user based authentication. Default values is empty string.\n\n**sendQueueSizeLimit**\n\nQueue size limit in bytes. This option has no effect in `Message` mode. Default is `8 MiB`.\n\n**tls**\n\nEnable TLS for socket.\n\n**tlsOptions**\n\nOptions to pass to tls.connect when tls is true.\n\nFor more details, see following documents\n* [tls.connect()](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback)\n* [tls.createSecureContext()](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options)\n\n**internalLogger**\n\nSet internal logger object for FluentLogger. Use `console` by default.\nThis logger requires `info` and `error` method.\n\n## Examples\n### Winston Integration\nAn example of integrating with Winston can be found at [`./example/winston`](./example/winston).\n\nYou will need Docker Compose to run it. After navigating to `./example/winston`, run `docker-compose up` and then `node index.js`. You should see the Docker logs having an `\"it works\"` message being output to FluentD.\n\n## License\n\nApache License, Version 2.0.\n\n[fluent-logger-python]: https://github.com/fluent/fluent-logger-python\n\n\n## About NodeJS versions\n\nThis package is compatible with NodeJS versions \u003e= 6.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluent%2Ffluent-logger-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluent%2Ffluent-logger-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluent%2Ffluent-logger-node/lists"}