# dk-logger

> A logger for **Digital Kites** processes.

Latest version **2.1.8** (published 2020-09-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install dk-logger
pnpm add dk-logger
yarn add dk-logger
bun add dk-logger
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.8 |
| Published | 2020-09-28 |
| First published | 2019-09-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 17.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | mohammed_way2, yanalavishnu |

## Links

- npm: https://www.npmjs.com/package/dk-logger
- npm.io page: https://npm.io/package/dk-logger

## Dependencies (4)

- [pm2](https://npm.io/package/pm2.md) ^4.4.0
- [async](https://npm.io/package/async.md) ^3.1.0
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.1
- [@google-cloud/error-reporting](https://npm.io/package/@google-cloud/error-reporting.md) ^2.0.0

## Recent versions

- 2.1.8 (latest) — 2020-09-28
- 2.1.7 — 2020-08-06
- 2.1.6 — 2020-02-22
- 2.1.5 — 2020-01-30
- 2.1.4 — 2019-11-11
- 2.1.2 — 2019-11-02
- 1.2.4 — 2019-10-31
- 1.2.3 — 2019-10-31
- 2.1.0 — 2019-10-30
- 1.2.2 — 2019-10-30
- 2.0.5 — 2019-10-30
- 2.0.4 — 2019-10-29
- 2.0.3 — 2019-10-29
- 2.0.2 — 2019-10-26
- 2.0.1 — 2019-10-26
- … 5 more at https://npm.io/package/dk-logger/versions

## README

# dk_logger

A logger for **Digital Kites** processes.

## Installation

Make sure you have [Node.js](http://nodejs.org/) and [Npm](https://www.npmjs.com/) installed.

```sh
npm install dk-logger@latest
```

This will be added to your package.json dependencies.

## Usage

```js
const dk_logger = require('dk-logger');

dk_logger.setApiKey('YOUR API KEY');
dk_logger.setErrorReportObj({
  projectId: 'PROJECT ID', // required
  credentialsPath: 'PROJECT CREDENTIALS FILE PATH' // optional
});

const obj = {
    app_ip:"x.x.x.x",  // optional 
    app_name:"your pm2 app name",  // optional
    app_id: 1, // pm2 process id (optional)
    date: Math.floor(new Date().setHours(0, 0, 0, 0) / 1000), // your date epoch in seconds
    time: Math.floor(Date.now() / 1000), // your time epoch in seconds
    message: "some message",//your message
    status: "online",
    log_level:"info" //["fatal", "error", "warn","info","debug"]
}

dk_logger.save(obj);
```

#### How to include in your process:

```js
//Note:Must include this in the first line of your file(which is started with pm2).
//Note:Make sure this snippet runs in production envirnoment.
//NOTE: custom error messages(other than errors originated) should be passed as --> message:new Error(YOUR ERROR), all other errors as --> message: YOUR ERROR 
const dk_logger = require('dk-logger');

dk_logger.setApiKey('YOUR API KEY');
//To send error logs to Google
dk_logger.setErrorReportObj({
  projectId: 'PROJECT ID', // required
  credentialsPath: 'PROJECT CREDENTIALS FILE PATH' // optional
});

process.on('uncaughtException', function(e) {
  console.error('[uncaughtException] app will be terminated: ', e);
  const obj = {
    date: Math.floor(new Date().setHours(0, 0, 0, 0) / 1000), // your date epoch in seconds
    time: Math.floor(Date.now() / 1000), // your time epoch in seconds
    message: e.message,
    status: "stopped",
    log_level:"error"
  }
  dk_logger.save(obj).then(function(){
    process.exit(0);
    throw new Error(e.message);
  });
});
```

---
_Source: https://npm.io/package/dk-logger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
