Comments (8)
what if https://play.golang.org/p/t3SBYkF4YRl or https://play.golang.org/p/eNtrQBmUrSn ?
from log.
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.
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.
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.
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.
I create a PR based on "Header" callback idea, #42 please take a look and comment, thanks!
from log.
Checked your PR #42 and it looks perfect to me. Easy, elegant, no frills, just plain effective.
from log.
thanks, I merged and tagged v1.0.73
from log.
Related Issues (20)
- Add golangci-lint HOT 1
- Compatibility with rs/logbench HOT 18
- Msg() truncate strings with single quotes when having a custom Formatter HOT 3
- log With() HOT 12
- MultiWriter based on io.Writer HOT 8
- Single Quotation Mark HOT 7
- FileWriter Filename HOT 12
- it does not rotate if you have a TimeFormat defines and a MaxSize then reach MaxSize with the same TimeFormat HOT 6
- [QUESTION] - How to use graylog with this library HOT 3
- Long filename in `caller` HOT 3
- 有内置日志采样功能的计划吗? HOT 5
- v1.0.75 tag 名称是否需要调整一下? HOT 1
- Time() always format with local timezone HOT 1
- 如何把所有日志放一个文件 HOT 2
- 启动多个应用程序写入同一日志文件 HOT 1
- [FEATURE REQUEST] - Allow logging in CSV format HOT 2
- How about supporting global level? HOT 6
- FileWriter comment mentions MaxAge but that field does not exist HOT 1
- Gzip examples writes truncated file HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from log.