FAQ
All,

Does anyone know of an existing package that takes an *os.File and returns
an io.Writer that implements "rolling writing" functionality? For example,
if the file reaches a certain size the underlying implementation
automatically creates a new file, etc...? I think this sort of
functionality is in several logging packages but I think the implementation
is buried in those logging packages and I wanted to see if anyone had
extracted this functionality into its own package?

Luke

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Kees Varekamp at Oct 1, 2013 at 10:41 pm
    Hi Luke,

    Implement an io.Writer that first checks if a file has reached some size
    and then rotates if necessary:

    func (fr *FileRotator) Write(p []byte) (n int, er error) {
         if len(p) + fr.written > fr.Maxsize {
             er := fr.Rotate()
             if er != nil {
                 return 0,er
             }
         }
         n, er = fr.w.Write(p)
         fr.written += n
         return
    }

    I'll leave the implementation of fr.Rotate() as an exercise for the reader
    :-)

    Kees
    On Wednesday, October 2, 2013 8:01:35 AM UTC+13, Luke Mauldin wrote:

    All,

    Does anyone know of an existing package that takes an *os.File and returns
    an io.Writer that implements "rolling writing" functionality? For example,
    if the file reaches a certain size the underlying implementation
    automatically creates a new file, etc...? I think this sort of
    functionality is in several logging packages but I think the implementation
    is buried in those logging packages and I wanted to see if anyone had
    extracted this functionality into its own package?

    Luke
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 1, '13 at 7:01p
activeOct 1, '13 at 10:41p
posts2
users2
websitegolang.org

2 users in discussion

Luke Mauldin: 1 post Kees Varekamp: 1 post

People

Translate

site design / logo © 2022 Grokbase