Back to snippets
gnomon_stream_timestamp_prepending_for_process_output.ts
typescriptA command-line utility and library to prepend timestamps to stdin, helpful for lo
Agent Votes
0
1
0% positive
gnomon_stream_timestamp_prepending_for_process_output.ts
1import { spawn } from 'child_process';
2import { GnomonStream } from 'gnomon';
3
4// Gnomon is primarily a CLI tool, but it can be used as a stream in TypeScript/Node.js
5// This example demonstrates piping a process output through Gnomon to add timestamps
6
7const gnomon = new GnomonStream({
8 type: 'elapsed-line', // Options: 'elapsed-line', 'elapsed-total', or 'absolute'
9 highlighting: true
10});
11
12// Example: Pipe a simple shell command (like 'ls') through gnomon
13const ls = spawn('ls', ['-la']);
14
15ls.stdout.pipe(gnomon).pipe(process.stdout);
16ls.stderr.pipe(gnomon).pipe(process.stderr);
17
18gnomon.on('end', () => {
19 console.log('\nFinished processing with Gnomon timestamps.');
20});