Coder Social home page Coder Social logo

Comments (8)

phuslu avatar phuslu commented on May 19, 2024

what if https://play.golang.org/p/t3SBYkF4YRl or https://play.golang.org/p/eNtrQBmUrSn ?

from log.

syncplify avatar syncplify commented on May 19, 2024

That's a good approach. I'll toy a little bit with it on Monday, to see what I can do.

The "log header" part each time a file is rotated remains an open issue. I could add lines by logging them of course, but if lines come in at the same time from other groutines, the header may end up intertwined with those lines. Headers should be "atomically written".

But thank you for pointing me the right direction regarding writer-chaining to address the W3C log format. Much appreciated.

from log.

phuslu avatar phuslu commented on May 19, 2024

For the "log header", this is a problem. When I implementing csv logger, I also encountered this problem.

Currently I have no good ideas to solve this problem in a pretty way.

from log.

phuslu avatar phuslu commented on May 19, 2024

A straightforward way is, add a LogHeader callback to FileWriter

type FileWriter struct {
	// LogHeader specifies an optional log header after rotation
	LogHeader func(fileinfo os.FileInfo) []byte
}

But this a little ugly, because it tied logger and writer. Any thoughts/comments ?

from log.

syncplify avatar syncplify commented on May 19, 2024

I agree, this is an "easy" solution but comes with a "cost" (logger and writer being tied as you mentioned). On the other hand the weight of this tie wouldn't be heavier than the Rotate callback in my humble opinion. Leaving the callback function pointer to nil would ensure the Writer works just like it does now, but would provide an option for those who need it to specify a custom behavior that only applies to this writer.

If, on the other hand, we think that a custom atomic header would be useful for other writers as well, then maybe we can come up with a dedicated additional interface{} that all Writers implement (on top of io.Writer and io.WriteCloser) although this could end up being slightly more cumbersome to implement.

One more possibility could be (consequences to be evaluated) to "derive" a descendant of FileWriter... something like:

type FileWriterWithHeaderCallback struct {
    FileWriter
    /...
}

(but this may or may not be a rabbit hole, just put it out there as food for thoughts)

from log.

phuslu avatar phuslu commented on May 19, 2024

I create a PR based on "Header" callback idea, #42 please take a look and comment, thanks!

from log.

syncplify avatar syncplify commented on May 19, 2024

Checked your PR #42 and it looks perfect to me. Easy, elegant, no frills, just plain effective.

from log.

phuslu avatar phuslu commented on May 19, 2024

thanks, I merged and tagged v1.0.73

from log.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.