<commit_before>[![Go Report Card](http://goreportcard.com/badge/client9/reopen)](http://goreportcard.com/report/client9/reopen) [![GoDoc](https://godoc.org/github.com/client9/reopen?status.svg)](https://godoc.org/github.com/client9/reopen) [![Coverage](http://gocover.io/_badge/github.com/client9/reopen)](http://gocover.io/github.com/client9/reopen)

Makes a standard os.File "reopenable writer" and allows SIGHUP signals
to reopen log files, as needed by
[logrotated](https://fedorahosted.org/logrotate/).  This is inspired
by the C/Posix
[freopen](http://pubs.opengroup.org/onlinepubs/009695399/functions/freopen.html)

The simple version `reopen.NewFileWriter` does unbuffered writing.  A
call to `.Reopen` closes the existing file handle, and then re-opens
it using the original filename.

The more advanced version `reopen.NewBufferedFileWrite` buffers input
and flushes when the internal buffer is full (with care) or if 30 seconds has
elapsed.

Samples are in `example1` and `example2`.  The `run.sh` scripts are a
dumb test where the file is rotated underneath the server, and nothing
is lost.  (not the most robust test but gives you an idea)


Here's some sample code.
<commit_msg>badges<commit_after>[![Go Report Card](http://goreportcard.com/badge/client9/reopen)](http://goreportcard.com/report/client9/reopen) [![GoDoc](https://godoc.org/github.com/client9/reopen?status.svg)](https://godoc.org/github.com/client9/reopen) [![Coverage](http://gocover.io/_badge/github.com/client9/reopen)](http://gocover.io/github.com/client9/reopen) [![license](http://img.shields.io/badge/license-apache_2.0-red.svg?style=flat)](https://raw.githubusercontent.com/client9/reopen/master/LICENSE)

Makes a standard os.File "reopenable writer" and allows SIGHUP signals
to reopen log files, as needed by
[logrotated](https://fedorahosted.org/logrotate/).  This is inspired
by the C/Posix
[freopen](http://pubs.opengroup.org/onlinepubs/009695399/functions/freopen.html)

The simple version `reopen.NewFileWriter` does unbuffered writing.  A
call to `.Reopen` closes the existing file handle, and then re-opens
it using the original filename.

The more advanced version `reopen.NewBufferedFileWrite` buffers input
and flushes when the internal buffer is full (with care) or if 30 seconds has
elapsed.

Samples are in `example1` and `example2`.  The `run.sh` scripts are a
dumb test where the file is rotated underneath the server, and nothing
is lost.  (not the most robust test but gives you an idea)


Here's some sample code.

{'fraction_non_alphanumeric': 0.12252180808881839, 'fraction_numerical': 0.01625693893735131, 'mean_word_length': 5.12378640776699, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '31479', 'n_tokens_mistral': 854, 'n_tokens_neox': 809, 'n_words': 233}