{"id":18487160,"url":"https://github.com/logdna/nodejs","last_synced_at":"2025-04-08T20:30:47.101Z","repository":{"id":44609920,"uuid":"63717341","full_name":"logdna/nodejs","owner":"logdna","description":"Node.js library for logging to LogDNA","archived":true,"fork":false,"pushed_at":"2022-02-04T19:06:15.000Z","size":284,"stargazers_count":74,"open_issues_count":1,"forks_count":66,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-10-14T03:18:37.276Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/logdna.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-19T18:12:52.000Z","updated_at":"2023-12-23T19:36:15.000Z","dependencies_parsed_at":"2022-08-28T16:21:25.677Z","dependency_job_id":null,"html_url":"https://github.com/logdna/nodejs","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logdna%2Fnodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logdna%2Fnodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logdna%2Fnodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logdna%2Fnodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/logdna","download_url":"https://codeload.github.com/logdna/nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223343620,"owners_count":17129953,"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":[],"created_at":"2024-11-06T12:50:15.861Z","updated_at":"2024-11-06T12:51:30.059Z","avatar_url":"https://github.com/logdna.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://app.logdna.com\"\u003e\n    \u003cimg height=\"95\" width=\"201\" src=\"https://raw.githubusercontent.com/logdna/artwork/master/logo%2Bnode.png\"\u003e\n  \u003c/a\u003e\n  \u003cp align=\"center\"\u003eNode.js library for logging to \u003ca href=\"https://app.logdna.com\"\u003eLogDNA\u003c/a\u003e\u003c/p\u003e\n\u003c/p\u003e\n\n[![Build Status](https://travis-ci.org/logdna/nodejs.svg?branch=master)](https://travis-ci.org/logdna/nodejs)  [![Known Vulnerabilities](https://snyk.io/test/npm/logdna/badge.svg)](https://snyk.io/test/npm/logdna)\n\n---\n\n# Deprecation Notice\n\nThis package has been deprecated in favor of the [@logdna/logger](https://www.npmjs.com/package/@logdna/logger) package.\nPlease use `@logdna/logger` instead of the `logdna` package.\n\n---\n\n* **[Install](#install)**\n* **[Setup](#setup)**\n* **[Usage](#usage)**\n* **[API](#api)**\n* **[Client Side Support](#client-side)**\n* **[Bunyan Stream](#bunyan-stream)**\n* **[Winston Transport](#winston-transport)**\n* **[AWS Lambda Support](#aws-lambda-support)**\n* **[License](#license)**\n\n\n## Install\n\n```javascript\n$ npm install --save logdna\n```\n\n## Setup\n```javascript\nvar Logger = require('logdna');\nvar options = {\n    hostname: myHostname,\n    ip: ipAddress,\n    mac: macAddress,\n    app: appName,\n    env: envName\n};\n\n// Defaults to false, when true ensures meta object will be searchable\noptions.index_meta = true;\n\n// Add tags in array or comma-separated string format:\noptions.tags = ['logging', 'nodejs', 'logdna'];\n// or:\noptions.tags = 'logging,nodejs,logdna';\n\n// Create multiple loggers with different options\nvar logger = Logger.createLogger(apikey, options);\n\n```\n_**Required**_\n* [LogDNA Ingestion Key](https://app.logdna.com/manage/profile)\n\n_**Optional**_\n* Hostname - *(String)* - max length 32 chars\n* MAC Address - *(String)*\n* IP Address - *(String)*\n* Max Length - *(Boolean)* - formatted as options.max_length\n* Index Meta - *(Boolean)* - formatted as options.index_meta\n* logdna_url - *(String)*  - alternate ingest URL\n\n## Usage\n\nAfter initial setup, logging is as easy as:\n```javascript\n// Simplest use case\nlogger.log('My Sample Log Line');\n\n// Add a custom level\nlogger.log('My Sample Log Line', 'MyCustomLevel');\n\n// Include an App name with this specific log\nlogger.log('My Sample Log Line', { level: 'Warn', app: 'myAppName'});\n\n// Pass an associated object along with a specific line as metadata...\nvar meta = {\n    foo: 'bar',\n    nested: {\n      nest1: 'nested text'\n    }\n};\n\nvar opts = {\n  level: 'warn',\n  meta: meta\n};\n\nlogger.log('My Sample Log Line', opts);\n```\n\nFor more options, this module also offers:\n```javascript\n// We support the following six levels\nlogger.info('My Sample Log Line');\nlogger.warn('My Sample Log Line');\nlogger.debug('My Sample Log Line');\nlogger.error('My Sample Log Line');\nlogger.fatal('My Sample Log Line');\n\n// Functions above also accept additional options\nlogger.trace('My Sample Log Line', { app: 'myAppName'});\n\nvar opts = {\n  level: 'trace',\n  meta: {\n    foo: 'bar',\n    nested: {\n      nest1: 'nested text'\n    }\n  }\n};\n\n// Functions above also pass any associated objects along as metadata\nlogger.trace('My Sample Log Line', opts);\n\n// To add metadata to every log line created by the logger instance:\nlogger.addMetaProperty('fizz', 'buzz');\n\n// To overwrite the default `fizz` metadata from the logger instance:\nvar opts = {\n  meta: {\n    fizz: 'not-buzz'\n  }\n};\n\nlogger.log('My Sample Log Line', opts);\n\n```\nYou will see the outputs in your LogDNA dashboard.\n\n## API\n\n### createLogger(key, [options])\n---\n#### key\n\n* _**Required**_\n* Type: `String`\n* Values: `YourIngestionKey`\n\nThe [LogDNA Ingestion Key](https://app.logdna.com/manage/profile) associated with your account.\n\n#### options\n\n##### app\n\n* _**Optional**_\n* Type: `String`\n* Default: `''`\n* Values: `YourCustomApp`\n* Max Length: `32`\n\nThe default app passed along with every log sent through this instance.\n\n##### hostname\n\n* _**Optional**_\n* Type: `String`\n* Default: `''`\n* Values: `YourCustomHostname`\n* Max Length: `32`\n\nThe default hostname passed along with every log sent through this instance.\n\n##### env\n\n* _**Optional**_\n* Type: `String`\n* Default: `''`\n* Values: `YourCustomEnvironment`\n* Max Length: `32`\n\nThe default environment passed along with every log sent through this instance.\n\n##### index_meta\n\n* _**Optional**_\n* Type: `Boolean`\n* Default: `false`\n\nWe allow meta objects to be passed with each line. By default these meta objects will be stringified and will not be searchable,\nbut will be displayed for informational purposes.\n\nIf this option is turned to true then meta objects will be parsed and will be searchable up to three levels deep. Any fields deeper than three levels will be stringified and cannot be searched.\n\n*WARNING* When this option is true, your metadata objects across all types of log messages MUST have consistent types or the metadata object may not be parsed properly!\n\n##### cleanUpSIGTERM\n\n\n*WARNING* Deprecated, you will have to opt-in and call cleanUpAll, where appropriate. AWS Lambda users have issues with listening on SIGTERM/SIGINT\n\n##### cleanUpSIGINT\n\n*WARNING* Deprecated, you will have to opt-in and call cleanUpAll, where appropriate. AWS Lambda users have issues with listening on SIGTERM/SIGINT\n\n##### ip\n\n* _**Optional**_\n* Type: `String`\n* Default: `''`\n* Values: `10.0.0.1`\n\nThe default IP Address passed along with every log sent through this instance.\n\n##### level\n\n* _**Optional**_\n* Type: `String`\n* Default: `Info`\n* Values: `Debug`, `Trace`, `Info`, `Warn`, `Error`, `Fatal`, `YourCustomLevel`\n* Max Length: `32`\n\nThe default level passed along with every log sent through this instance.\n\n##### mac\n\n* _**Optional**_\n* Type: `String`\n* Default: `''`\n* Values: `C0:FF:EE:C0:FF:EE`\n\nThe default MAC Address passed along with every log sent through this instance.\n\n##### max_length\n\n* _**Optional**_\n* Type: `Boolean`\n* Default: `true`\n\nBy default the line has a maximum length of 32000 chars, this can be turned off with the value false.\n\n##### timeout\n\n* _**Optional**_\n* Type: `Integer`\n* Default: `180000`\n* Max Value: `300000`\n\nThe length of the timeout on the POST request that is sent to LogDNA.\n\n##### with_credentials\n\n* _**Optional**_\n* Type: `Boolean`\n* Default: `false`\n\nThe withCredentials option passed to the request library. In order to make CORS requests this value is set to false by default.\n\n### log(line, [options])\n---\n#### line\n\n* _**Required**_\n* Type: `String`\n* Default: `''`\n* Max Length: `32000`\n\nThe line which will be sent to the LogDNA system.\n\n#### options\n\nPlease note that if you are using variables for any of the below options, their values may change in between the line being logged and the batch of lines being flushed to our servers. If your variables change frequently, we highly recommend copying the value instead of referencing the variable directly.\n\n##### level\n\n* _**Optional**_\n* Type: `String`\n* Default: `Info`\n* Values: `Debug`, `Trace`, `Info`, `Warn`, `Error`, `Fatal`, `YourCustomLevel`\n* Max Length: `32`\n\nThe level passed along with this log line.\n\n##### app\n\n* _**Optional**_\n* Type: `String`\n* Default: `''`\n* Values: `YourCustomApp`\n* Max Length: `32`\n\nThe app passed along with this log line.\n\n##### env\n\n* _**Optional**_\n* Type: `String`\n* Default: `''`\n* Values: `YourCustomEnvironment`\n* Max Length: `32`\n\nThe environment passed along with this log line.\n\n##### meta\n\n* _**Optional**_\n* Type: `JSON`\n* Default: `null`\n\nA meta object that provides additional context about the log line that is passed.\n\n##### index_meta\n\n* _**Optional**_\n* Type: `Boolean`\n* Default: `false`\n\nWe allow meta objects to be passed with each line. By default these meta objects will be stringified and will not be searchable,\nbut will be displayed for informational purposes.\n\nIf this option is turned to true then meta objects will be parsed and will be searchable up to three levels deep. Any fields deeper than three levels will be stringified and cannot be searched.\n\n*WARNING* When this option is true, your metadata objects across all types of log messages MUST have consistent types or the metadata object may not be parsed properly!\n\n##### timestamp\n\n* _**Optional**_\n* Default: `Date.now()`\n\nA timestamp in ms, must be within one day otherwise it will be dropped and Date.now() will be used in its place.\n\n### flushAll(callback)\n---\nA function that flushes all existing loggers that are instantiated by createLogger.\n\nReturns the callback with an error as a first argument if one of the loggers failed to flush.\n\n### cleanUpAll()\n---\nA function that flushes all existing loggers that are instantiated by createLogger, and then removes references to them. Should only be called when you are finished logging.\n\n## Default Metadata\n\nIf you'd like to add metadata to each log line generated by the logger instance rather than adding metadata to each log line individually, use the following meta functions.\n\nThe key-value pair that you add will be automatically added to each log line's metadata. However, if you pass in any `meta` keys to an individual line instance using the `options` argument, those will overwrite any corresponding values that were set by the logger's default metadata.\n\n### addMetaProperty(key, value)\n---\nA function that adds `key`/`value` pair into the logger's default meta.\n\n### removeMetaProperty(key)\n---\nA function that removes the `key` and associated `value` from the logger's default meta.\n\n## Client Side\nBrowserify Support in version ^3.0.1\n```javascript\nconst Logger = require('logdna');\nconst logger = Logger.createLogger('API KEY HERE', {\n    hostname:'ClientSideTest'\n    , app: 'sequence'\n    , index_meta: true\n});\n\nconst date = new Date().toISOString();\nconst logme = (callback) =\u003e {\n    for (var i = 0; i \u003c 10; i++) {\n        logger.log('Hello LogDNA Test ' + date, { meta: { sequence: i }});\n    }\n    return callback \u0026\u0026 callback();\n};\n\n\nsetInterval(logme, 5000);\n```\nIf the above snippet is saved as a file main.js. Then with browserify you can convert this to a bundle.js file.\n```\nbrowserify main.js -o bundle.js\n```\nThe bundle.js file can be included like any other script.\n```\n\u003cscript src=\"bundle.js\"\u003e\u003c/script\u003e\n```\nWhen using NodeJS inside a browser, the domain needs to be whitelisted in your LogDNA organization settings\n\n## Bunyan Stream\n\nFor Bunyan Stream support please reference our [logdna-bunyan](https://github.com/logdna/logdna-bunyan/) module\n\n## Winston Transport\n\nFor Winston support please reference our [logdna-winston](https://github.com/logdna/logdna-winston/) module\n\n## AWS Lambda Support\n\nAWS Lambda allows users to add logging statements to their Lambda Functions. You can choose to setup the logger\nas shown above, or you can override the console.log, console.error statements. AWS Lambda overrides the console.log, console.error, console.warn, and console.info functions as indicated [here](http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-logging.html), within the scope of the handler (main) function. You can setup an override as follows:\n\n```javascript\n'use strict';\n\nconst https = require('https');\nconst Logger = require('logdna');\n\nconst options = {\n    env: 'env'\n    , app: 'lambda-app'\n    , hostname: 'lambda-test'\n    , index_meta: true\n};\n\nvar _log = console.log;\nvar _error = console.error;\n\nvar logger = Logger.setupDefaultLogger('YOUR API KEY', options);\n\n\nvar log = function() {\n    logger.log([...arguments].join(' '));\n    _log.apply(console, arguments);\n};\n\nvar error = function() {\n    logger.error([...arguments].join(' '));\n    _error.apply(console, arguments);\n};\n\n/**\n * Pass the data to send as `event.data`, and the request options as\n * `event.options`. For more information see the HTTPS module documentation\n * at https://nodejs.org/api/https.html.\n *\n * Will succeed with the response body.\n */\nexports.handler = (event, context, callback) =\u003e {\n    console.log = log;\n    console.error = error;\n\n    // Your code here\n    console.log('How bout normal log');\n    console.error('Try an error');\n\n    callback();\n};\n```\n\n## HTTP Exception Handling\nIf the logger does not receive a successful response from the server, it tries to send it again in the period set in `options` (`options.retryTimeout`) or the default `BACKOFF_PERIOD`. It makes three (or `RETRY_TIMES`) attempts to resend the logs. If none of the attempts was successful, the failed logs will be preserved and attempted to send with the next request. The size of the retry buffer that saves logs that failed to send and the retry timeout are configurable via:\n\n``` javascript\nvar options = {\n    failedBufRetentionLimit: 10000000 // bytes\n    retryTimeout: 3000 // milliseconds\n    retryTimes: 5\n};\n\nvar logger = Logger.setupDefaultLogger(apikey, options);\n```\n\n## Troubleshooting\n\nThis library takes advantage of [`util.debuglog()`](https://nodejs.org/api/util.html#util_util_debuglog_section) to\noutput details about message handling such as:\n  - When the logger receives a message (useful for indirect usages such as bunyan, winston, or custom wrappers)\n  - An indication of when messages are actually sent to the API (they may be buffered for a time)\n  - An indication of whether the API responds with a success or failure.\n\nFor cases where you do not see your log messages appear in LogDNA, these debug messages can make it easier to tell if\nthe problem is on the sending or receiving end.  They can also provide valuable information which can speed up diagnosis\nif you need to work with the LogDNA support staff.\n\nYou can enable debug messages with the `NODE_DEBUG=logdna` environment variable. See the `util.debuglog()`\ndocumentation for more information.\n\n## License\n\nMIT © [LogDNA](https://logdna.com/)\n\n*Happy Logging!*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogdna%2Fnodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flogdna%2Fnodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogdna%2Fnodejs/lists"}