Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer use logging in butil or glog? #2696

Open
oathdruid opened this issue Jul 17, 2024 · 6 comments
Open

Prefer use logging in butil or glog? #2696

oathdruid opened this issue Jul 17, 2024 · 6 comments
Labels
enhancement improvements on existing features

Comments

@oathdruid
Copy link
Contributor

Is your feature request related to a problem? (你需要的功能是否与某个问题有关?)
I see there is a simple logging mechanism delivered along with brpc in butil/logging.cc. I'm not sure whether it is aimed to be production ready or just a default demo. It lack some important feature, like rotation. But on the other hand, i see @chenBright is still try to optimize it for performance month ago.

Describe the solution you'd like (描述你期望的解决方法)
I want to know, whether a logging implementation is in brpc's road map, or we just depend on glog's ecosystem?

Describe alternatives you've considered (描述你想到的折衷方案)

Additional context/screenshots (更多上下文/截图)

@chenBright
Copy link
Contributor

I currently use butil/logging in production, which was the impetus for implementing asynchronous logging in butil/logging. I believe that a subset of users use butil/logging.

I have plans to support log rotation in butil/logging. In my opinion, there is no need to use glog. Of course, it is not mandatory. In addition to using glog, users can also implement their own LogSink, such as ComlogSink.

@oathdruid
Copy link
Contributor Author

oathdruid commented Jul 17, 2024

I just finish exporting some wait-free & malloc-free async logger practice used internal in baidu [documented here]. Integrate these to LOG macro leaves a disaster of tricks internal.

If there is a plan of making a new framework, i think maybe we could make some proper plugin point to let the integration easier.

@chenBright
Copy link
Contributor

What are the problems with the integration through LogSink?

@oathdruid
Copy link
Contributor Author

  • To remove the front end copy, I need to replace the implementation of LogMessage.stream()
  • in glog sending to sink have some internal locks

@chenBright
Copy link
Contributor

Make LogStream a virtual base class as follows:

class LogStream :  public std::ostream {
    LogStream(std::streambuf& streambuf) : std::ostream(&streambuf) {}
    virtual void SetSourceLocation(const SourceLocation& sl) = 0;
    virtual void Flush() = 0;
}

At the same time, a LogStreamFactory is needed to create LogStream instances, as follows:

class LogStreamFactory {
    virtual LogStream* Create() = 0;
    virtual void Destroy(LogStream* log_stream) = 0;
};

Is this design feasible?

@chenBright chenBright added the enhancement improvements on existing features label Jul 22, 2024
@oathdruid
Copy link
Contributor Author

Good enough for me. I have a similar design here. A std::streambuf plugin point is easier to do the integration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improvements on existing features
Projects
None yet
Development

No branches or pull requests

2 participants