docs: add example to count ERROR lines in a log file (#236)#243
docs: add example to count ERROR lines in a log file (#236)#243shreyaabaranwal wants to merge 2 commits into
Conversation
Signed-off-by: shreyaabaranwal <shreyabaranwal229@gmail.com>
Signed-off-by: shreyaabaranwal <shreyabaranwal229@gmail.com>
|
Great contribution, @shreyaabaranwal, thanks a lot! It might be a nice idea to tie these examples in more directly with the ones in the README, mightn't it? For example, we start with: contents, err := script.File("test.txt").String()and work our way through things like counting error lines (to your point). What if we made each of these examples a standalone program, and then we could link from the README to the full listing? If you feel like adding more complicated examples, by all means do, but we should probably start with these. For examples that need to read a specific file, we should probably come up with a general solution to: // Check if examples/app.log exists, otherwise fallback to app.log.My instinct is that people would naturally run |
Hi! Following up on #236 — here's a first example to get the examples/ directory started.
I went with something straight out of everyday ops life: counting ERROR lines in a log file. Anyone who's stared at logs during an incident knows this one — it's basically
grep ERROR app.log | wc -l, but here it's done with script:I really like how cleanly the pipe-style API reads here — it maps almost one-to-one to the shell command, which I think makes it a nice, relatable first example for newcomers.
I've included a small sample
examples/app.logso it runs out of the box, and verified everything locally withgo run,gofmt -l, andgo vet(all clean).Happy to add a couple more examples in the same spirit if you'd like — just wanted to start with one and get your feedback on the format first.
Closes #236