# logdir

> dump text streams into a log directory and read the data back intelligently

Latest version **0.0.3** (published 2013-05-13) · MIT license · 0 weekly downloads

## Install

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

## 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.0.3 |
| Published | 2013-05-13 |
| First published | 2013-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | James Halliday |
| Maintainers | substack |
| Keywords | log, data, timestamp, slice, follow, stream |

## Links

- npm: https://www.npmjs.com/package/logdir
- Repository: https://github.com/substack/logdir
- npm.io page: https://npm.io/package/logdir

## Dependencies (3)

- [through](https://npm.io/package/through.md) ~2.3.1
- [inherits](https://npm.io/package/inherits.md) ~1.0.0
- [slice-file](https://npm.io/package/slice-file.md) ~0.1.5

## 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.0.3 (latest) — 2013-05-13
- 0.0.2 — 2013-05-04
- 0.0.1 — 2013-04-21
- 0.0.0 — 2013-04-21

## README

# logdir

dump text streams into a directory and read the data back intelligently

[![build status](https://secure.travis-ci.org/substack/logdir.png)](http://travis-ci.org/substack/logdir)

# example

You can just create some writable streams and read the data back for a single
file:

``` js
var logdir = require('logdir');
var ld = logdir('/tmp/logdir');
var ws = ld.createWriteStream('robot');

ld.open('robot').follow(-5).pipe(process.stdout);
ws.write('beep boop\n');
```

```
$ node example/log.js
1366537631914 beep boop
1366537651318 beep boop
1366537657376 beep boop
```

or you can handle multiple log files at once:

```
var logdir = require('logdir');
var ld = logdir('/tmp/logdir');
var a = ld.createWriteStream('a');
var b = ld.createWriteStream('b');
setInterval(function () {
    a.write(String.fromCharCode(Math.random() * 26 + 97) + '\n');
}, 1000);

setInterval(function () {
    b.write(String.fromCharCode(Math.random() * 26 + 65) + '\n');
}, 1000);

ld.open([ 'a', 'b' ]).follow(-5).pipe(process.stdout);
```

```
$ node example/many.js 
a 1366537714837 v
b 1366537714838 Z
a 1366537715837 o
b 1366537715838 N
a 1366537716839 u
b 1366537716839 O
a 1366537717839 z
b 1366537717839 X
```

or you can even follow files that don't exist yet:

```
var logdir = require('logdir');
var ld = logdir('/tmp/logdir');
ld.open().follow(-5).pipe(process.stdout);
```

```
$ node all.js &
[1] 8545
$ echo $(node -pe 'Date.now()') beep >> /tmp/logdir/newfile
newfile 1366537884613 beep
$ echo $(node -pe 'Date.now()') boop >> /tmp/logdir/newfile
newfile 1366537892127 boop
$ echo $(node -pe 'Date.now()') whoa >> /tmp/logdir/anotherfile
anotherfile 1366537899027 whoa
$ kill %%
```

# methods

``` js
var logdir = require('logdir')
```

## var ld = logdir(dir)

Create a new logdir instance `ld` from a directory `dir`.

## var sf = ld.open(names)

Create a [slice-file](https://github.com/substack/slice-file) handle `sf` to
operate on all the `names` collectively.

If `names` is:

* a string - only slice a single log file of its name
* an array - slice the combined output of each log file, prepending `"$name "`
to the output stream
* undefined - slice the combined output of each log file in the directory and
watch the directory for new files when running `.follow()`

## sf.slice(begin, end)

Like `[].slice()`, but returns a stream of the line numbers that satisfy the
`begin` and `end` constraints.

This method comes from the underlying
[slice-file](https://github.com/substack/slice-file) module but may act on
multiple files at once intelligently.

## sf.follow(begin, end)

Returns an `sf.slice()` stream but watches the file and outputs all new content,
like `tail -f`.

This method comes from the underlying
[slice-file](https://github.com/substack/slice-file) module but may act on
multiple files at once intelligently.

# install

With [npm](https://npmjs.org) do:

```
npm install logdir
```

# license

MIT

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