Giter Site home page Giter Site logo

Comments (3)

bmoylan avatar bmoylan commented on May 31, 2024

I've pushed bmoylan/lumberjack#1 which proposes a change to lumberjack for rotating after a max time

from witchcraft-go-server.

bmoylan avatar bmoylan commented on May 31, 2024

Just found natefinch/lumberjack#76 which sounds like he probably would not accept the contribution

from witchcraft-go-server.

nmiyake avatar nmiyake commented on May 31, 2024

Thanks for raising this issue!

Took a look at the PR, and one thing to note is that, as currently implemented, I don't think that it makes the guarantee that log files are rotated at least once per time interval since the rotation check happens on Write. To make this guarantee, I do think that we'd need some goroutine that is running and would initiate rotation after the time period has elapsed. Although in general a running program will probably log to things like service logs at an interval where this isn't an issue, for logs that depend more on user actions (like event logs), this may be more of a possibility.

If at all possible, I would also like to avoid forking... Even though it's possible to fork or convert to an internal library here (since I don't think we expose the API externally at all), being on mainline would be nice.

What do you think of an implementation that would start a goroutine that does the file age comparison itself? I would imagine the high-level logic to be something like:

  • When creating/initializing logger, look for output file and record creation time
  • Start a timer that will fire at creation time + configured max log file age
  • When the timer fires, check creation time of output file
    • If it is the same as before, then perform rotation and restart timer
    • If it is different, then update timer to fire at new creation time + configured max log file age

There is a small edge case here (we determine that file is old, decide to call "rotate", but a write that triggers size-based rotation happens right before the "rotate" call and thus we double-rotate and have a log file with just one line), but I think it's small enough to be acceptable (and even when it's hit, you don't lost data -- just have a file that is strangely small). If we really cared about this, then we could make a wrapper struct that implements the Logger interface (and does this goroutine) and then perform the locking at this higher level.

from witchcraft-go-server.

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.