# clacks-logger

> Message logger plugin for clacks-p2p

Latest version **0.1.1** (published 2020-10-24) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2020-10-24 |
| First published | 2020-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alex Parker |
| Maintainers | alexanderparker |
| Keywords | clacks-p2p, logger, nodejs, p2p |

## Links

- npm: https://www.npmjs.com/package/clacks-logger
- Repository: https://github.com/AlexanderParker/clacks-logger
- Homepage: https://github.com/AlexanderParker/clacks-logger#readme
- Issues: https://github.com/AlexanderParker/clacks-logger/issues
- npm.io page: https://npm.io/package/clacks-logger

## 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

- 0.1.1 (latest) — 2020-10-24
- 0.1.0 — 2020-10-24

## README

# What is clacks-logger?

This is a plugin for the [clacks](https://github.com/AlexanderParker/clacks) p2p messaging system.

Its simple purpose is to log messages recieved by a clacks instance to the filesystem.

# Basic Usage

**Prerequisites**

This plugin requires [clacks](https://github.com/AlexanderParker/clacks)

**Installing**

    > npm install clacks-logger

**Loading**

Clacks plugins are loaded into an instance with the "extend" function, as demonstrated below (assuming you have created a clacksInstance already):
	
	Logger = require('clacks-logger')
    clacksInstance.extend(new Logger({<options>}))

**Options**

When instantiating the logger, you can provide some basic options if you wish

* **directory**: A string representing the base output directory that log will be written to (Default: "./logger").
* **type**: A string specifying what message types will be logged, which can be either "all", "message", or "announce" (Default: "all").

So to output logs to "./custom/location" and only log "message" types, you would do the following:

	clacksInstance.extend(new Logger({
		directory: './custom/location',
		type: 'message'
	}))

# Log Format

Every clacks peer has a unique identity hash, which is derived from their hostname. This forms the basis of the log path for the payload.

When a payload is logged, the filename is simply the current timestamp, determined by Date.now()

Thefore a payload will be logged to a file according to this pattern: "[base log directory]/[peer hash]/[timestamp]"

The contents of the log file is a JSON string with the following format:

	{
		peer: {<peer object>}
		payload: {<payload object>}
	}

For the format of the logged objects please refer to the primary clacks documentation accordingly:

* **[peer](https://github.com/AlexanderParker/clacks#peers)** - outlines the clacks peer object structure.
* **[payload](https://github.com/AlexanderParker/clacks#message-payload)** - outlines the clacks message payload structure.

# Test Example

You can view a test example in the [clacks-tests repository](https://github.com/AlexanderParker/clacks-tests/blob/main/plugins/clacks-logger.js).

# Contributing

If this project interests you, all contributions are welcome, from pull requests to suggestions and bug reports.

For clacks-logger specific issues, please use this [issue tracker](https://github.com/AlexanderParker/clacks-logger/issues) if you spot any problems, have general questions, ideas or feedback.

For core clacks-p2p issues, please use the main [issue tracker](https://github.com/AlexanderParker/clacks/issues) instead.

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