# api-bq-logger

> Log each & every api request ,response and error in BigQuery.

Latest version **1.0.17** (published 2019-04-16) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install api-bq-logger
pnpm add api-bq-logger
yarn add api-bq-logger
bun add api-bq-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 | 1.0.17 |
| Published | 2019-04-16 |
| First published | 2018-06-21 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 50.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Saurabh Kshirsagar |
| Maintainers | saurabhpk12 |
| Keywords | api-log, log-api, nodejs, bigquery, api-bigquery-logger |

## Links

- npm: https://www.npmjs.com/package/api-bq-logger
- Repository: https://github.com/saurabh-pk/api-bq-logger
- Homepage: https://github.com/saurabh-pk/api-bq-logger#readme
- Issues: https://github.com/saurabh-pk/api-bq-logger/issues
- npm.io page: https://npm.io/package/api-bq-logger

## Dependencies (3)

- [path](https://npm.io/package/path.md) ^0.12.7
- [util](https://npm.io/package/util.md) ^0.11.1
- [@google-cloud/bigquery](https://npm.io/package/@google-cloud/bigquery.md) ^1.3.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.0.17 (latest) — 2019-04-16
- 1.0.16 — 2019-03-27
- 1.0.15 — 2019-03-27
- 1.0.14 — 2018-12-07
- 1.0.13 — 2018-11-02
- 1.0.12 — 2018-11-02
- 1.0.11 — 2018-06-28
- 1.0.10 — 2018-06-27
- 1.0.9 — 2018-06-27
- 1.0.8 — 2018-06-25
- 1.0.7 — 2018-06-25
- 1.0.6 — 2018-06-25
- 1.0.5 — 2018-06-23
- 1.0.4 — 2018-06-23
- 1.0.3 — 2018-06-21
- … 3 more at https://npm.io/package/api-bq-logger/versions

## README

# api-bq-logger

Log each & every api request ,response and error in BigQuery.

[![npm](https://img.shields.io/npm/v/api-bq-logger.svg)](https://www.npmjs.com/package/api-bq-logger)

## Table of Contents

* [Install](#install)
* [Before using api-bq-logger](#before-using-api-bq-logger)
* [Create a Dataset](#create-a-dataset)
* [Create a Table in dataset](#create-a-table-in-dataset)
* [How to use](#how-to-use)
* [Helpdesk](#helpdesk)
* [License](#license)

## Install

#### npm

The best way to install and use api-bq-logger is with npm. It's registered
as [api-bq-logger](https://www.npmjs.com/package/api-bq-logger).

```
$ npm install api-bq-logger
```

#### Manual download

You can manually download api-bq-logger
from [Releases](https://github.com/saurabh-pk/api-bq-logger/releases).

#### From sources

If you want to use the development version of the plugin, use from source
manually. The development version may be unstable.

```
$ git clone https://github.com/saurabh-pk/api-bq-logger.git
$ cd api-bq-logger
$ npm install
```

## Before using api-bq-logger

1.  Select or create a Cloud Platform project.
    [Go to the projects page][projects]

1.  Make sure that billing is enabled for your project.
    [Enable billing][billing]

1.  BigQuery is automatically enabled in new projects.To activate BigQuery in a pre-existing project, go to Enable the BigQuery API.
    [Enable the API][enable_api]

1. To get authentication key file with a service account so you can access the API.
    1. Go to the **Create service account key** page in the [GCP Console](https://console.cloud.google.com/apis/credentials/serviceaccountkey).
     1.  From the  **Service account**  drop-down list, select  **New service account**.
     2.  Enter a name into the  **Service account name**  field.
     3. From the **Role** drop-down list, select **Project** > **Owner**.
     4.  Click  **Create**. A JSON file that contains your key downloads to your computer. Save this file in your projects base_dir.

[projects]:https://console.cloud.google.com/cloud-resource-manager
[billing]: https://cloud.google.com/billing/docs/how-to/modify-project
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=bigquery-json.googleapis.com
[auth]: https://cloud.google.com/docs/authentication/getting-started

    

## Create a Dataset

1. Go to the [BigQuery web UI](https://bigquery.cloud.google.com/)
1. Click the down arrow icon ![V](https://cloud.google.com/bigquery/images/icon-down-arrow.png) down arrow icon next to your project name in the navigation, then click **Create new dataset**.
1. Input the *DatasetName* for the **Dataset ID**.
1. Leave all of the other default settings in place and click **OK**.

## Create a Table in dataset

1. In the navigation, hover on the Dataset ID that you just created.
1. Click the down arrow icon down arrow icon ![V](https://cloud.google.com/bigquery/images/icon-down-arrow.png) next to the Dataset ID and click **Create new table**. Use the default values for all settings unless otherwise indicated.
1. Under Destination Table, enter the *TableName* for the **destination table name**.
1. In the Schema section, click the **Edit as Text** link. Then replace the contents of the Schema input area with the following schema:
```
request_id: STRING,
requested_api_url: STRING,
requesting_hostname: STRING,
requesting_ip:STRING,
request_method:STRING,
processing_time:STRING,
log_timestamp:TIMESTAMP,
log_type:STRING,
log_details:STRING, 
request_url:STRING,
request_from_user_agent:STRING,
request_referer:STRING,
request_params:STRING,
request_query:STRING,
request_body:STRING,
request_accessToken:STRING,
request_args:STRING,
request_headers:STRING    
```
**OR**

You can add schema manually using following schema details.
```
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|                                |               |               |
|    Column Name                 |   Type        |   Mode        |
|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | _ _ _ _ _ _ _ | _ _ _ _ _ _ _ |
|    request_id                  |   STRING      |   NULLABLE    |
|    requested_api_url           |   STRING      |   NULLABLE    |
|    requesting_hostname         |   STRING      |   NULLABLE    |
|    requesting_ip		 |   STRING      |   NULLABLE    |
|    request_method		 |   STRING      |   NULLABLE    |
|    processing_time		 |   STRING      |   NULLABLE    |
|    log_timestamp		 |   TIMESTAMP   |   NULLABLE    |
|    log_type                    |   STRING      |   NULLABLE    |
|    log_details		 |   STRING      |   NULLABLE    |
|    request_url                 |   STRING      |   NULLABLE    |
|    request_from_user_agent	 |   STRING      |   NULLABLE    |
|    request_referer             |   STRING      |   NULLABLE    |
|    request_params		 |   STRING      |   NULLABLE    |
|    request_query		 |   STRING      |   NULLABLE    |
|    request_body		 |   STRING      |   NULLABLE    |
|    request_accessToken         |   STRING      |   NULLABLE    |
|    request_args		 |   STRING      |   NULLABLE    |
|    request_headers		 |   STRING      |   NULLABLE    |
|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | _ _ _ _ _ _ _ | _ _ _ _ _ _ _ |
```

5. Click the **Create Table** button.

For more details visit,
[BigQuery Web UI](https://cloud.google.com/bigquery/bigquery-web-ui)

## How to use
  
1. Add following code in server/server.js after boot script.

```    
var apiBQLogger = require("api-bq- logger").factory(app,'KeyFileName','DatasetName','TableName',showLog,onErrorProcessExit);
```
where,
* **app** is an object of loopback
* **KeyFileName** name of the Google Cloud Bigquery service key file saved in base directory.
 * **DatasetName** Name of the dataset used to create logs table.
 * **TableName** Name of the table name which is use to save logs.
 * **showLog** Shows logs in console if set **true**, default is **false**
* **onErrorProcessExit** throws error and breaks the execution if set **true**, default is **false**

## Helpdesk

If you have any idea to improve this project or any problem using this, please
feel free to upload an [issue](https://github.com/saurabh-pk/api-bq-logger/issues).

The project is not actively maintained. No maintainer is paid, and most of
us are busy on our professional or personal works. Please understand that it may
take a while for an issue to be resolved.

## License

[GPL-3.0](LICENSE)

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