We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Buffered Logging

Our current logger, especially when writing to a file, is relatively slow. Every time we log a message, it writes to disk, no matter how large or small the message is. That's potentially a lot of disk I/O, and it can really slow down our entire application because many small writes are much slower than a few large writes.

Observability being the reason our app is slow is, frankly, embarrassing.

One solution is to use a buffered writer like bufio.Writer around the file. This allows us to write log messages to an in-memory buffer, and then that buffer is only written to disk when it's full.

bufferedFile := bufio.NewWriterSize(file, 1024)

Assignment

Buffer file logging writes.

LINKO_LOG_FILE=linko.access.log go run .

Run and submit the CLI tests from the root of the Linko repo.

If you create the buffered logger the way I did, it will introduce a subtle bug... but don't worry we'll fix it later!