# easytracker

> "A library to track javascript functions and log it"

Latest version **1.0.3** (published 2020-06-20) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install easytracker
pnpm add easytracker
yarn add easytracker
bun add easytracker
```

## 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 | 1.0.3 |
| Published | 2020-06-20 |
| First published | 2020-06-11 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | suman kumar suman |
| Maintainers | message4suman |
| Keywords | track, function, function, tracking, easy, loging, logs, loging |

## Links

- npm: https://www.npmjs.com/package/easytracker
- Repository: https://github.com/sumanvs/Tracker
- Homepage: https://github.com/sumanvs/Tracker#readme
- Issues: https://github.com/sumanvs/Tracker/issues
- npm.io page: https://npm.io/package/easytracker

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2020-06-20
- 1.0.2 — 2020-06-20
- 1.0.1 — 2020-06-13
- 1.0.0 — 2020-06-11

## README

# JS easytracker
Tracker is a library to track function execution. Primary objective of this JS library is to track/log the function using decorator syntax which makes it very easy to integrate into project and to analyse the function execution. Currently this library tracks function execution time, parameters and return value. All this is configurable. 

## Purpose and benifits

- Easy and seamless logging for js project
- Option to easily override console logs
- Option to set the log levels for tracker and for console both
- Option to set user data or identifer with logs
- Easy tracking of function with its parameter, return value. time taken
- All tracking is configurable
- Option to provide handler to handle all logs at one place in consistent structure (can help to store these tracking on server for analysing and reporting)

## Node example
[See node example](example/README.md)

## Installation

```bash
yarn add easytracker
```

## Usage
 
### import

```
import {track, Tracker} from 'easytracker';

or 

const {track, Tracker} = require( 'easytracker');
```

### configuration

```
// Config to setup the tracking parameters
Tracker.setConfig({
    trackParameters: true,  // default is true
    trackReturnValue: true,  // default is true
    trackTime: true, // default is true
    stringifiedObjects: true // default is true
});

/**
* Config to set level of tracking
* This parameters can help if we want to completely disable it for production or for specific levels
* Level can be "L", "I", "W", "E", "N" (aka: log, info, warn, error and none)
* Tracker.setLevel("N"); will disable all tracking
* Tracker.setLevel("W"); // will allow all warning and error level tracking
*/
Tracker.setLevel("L"); // default level is L

// To control the normal console in application based on level set for tracker
// Note: Tracker level must be set before calling this.
Tracker.overrideConsole();

// Config to set user context of all logs. This log will come with every tracking
Tracker.setUserData({'username': 'example'});

// Want to send logs to server. Here you can register a handler
Tracker.setServerHandle((printer, message) => {
    // DO NOT CALL console methods, as you have already overrode it earlier.
    // When this handler is set: 
    // Tracker will not print on console itslef. Use printer function as below to get message on console.
    printer(`FROM HANDLER: \n${message} \n`);
})

```

### tracking function

```
    @track()
    async initialConfig() {
       // Some function
    }
```

It will log in console like:
```
[Tracker] [Thu Jun 11 2020 19:59:52 GMT+0530 (India Standard Time)]
[Name]: initialConfig
[Is Async function]: true
```

### Option to override at specific function level and to provide level

```
    // default level for @track is "L"
    @track("I", "", {trackReturnValue: false})
    exampleFunction(val) {
         return 2+val;
    }

    exampleFunction(5);
```

It will log in console like 

```
[Tracker] [Sat Jun 13 2020 13:34:39 GMT+0530 (India Standard Time)]
[Function Name]: exampleFunction
[Class Name]: HelloWorld
[Is Async function]: false
[User]: {"username":"example"}
[Parameters]: [5]
[Time elapsed]: 1 milli-seconds
```

### To track normal function

```
// For normal function, wrap with track
const normalFunction = track("L", "myIden")(() => {
    return "this is a normal function";
})

normalFunction();

// It will log like
[Tracker]: [Sat Jun 20 2020 18:51:42 GMT+0530 (India Standard Time)]
[Identifier]: myIden
[Function Name]: anonymous
[User]: {"username":"example"}
[Return value]: "this is a normal function"
[Time elapsed]: 0 milli-seconds 

```

### Issues
If you run into decorator not supported issues. Follow this link `https://babeljs.io/docs/en/babel-plugin-proposal-decorators`

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