|
|
|
@ -58,13 +58,13 @@ func WithAccessSecret(as string) Option { |
|
|
|
|
|
|
|
|
|
type Option func(alc *options) |
|
|
|
|
|
|
|
|
|
type slsProducer struct { |
|
|
|
|
type Producer struct { |
|
|
|
|
pr *producer.Producer |
|
|
|
|
opts *options |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewSLSProducer 创建一个高性能的sls制造者
|
|
|
|
|
func NewSLSProducer(opts ...Option) *slsProducer { |
|
|
|
|
func NewSLSProducer(opts ...Option) *Producer { |
|
|
|
|
opt := defaultOptions() |
|
|
|
|
|
|
|
|
|
for _, o := range opts { |
|
|
|
@ -78,19 +78,19 @@ func NewSLSProducer(opts ...Option) *slsProducer { |
|
|
|
|
producerInstance := producer.InitProducer(producerConfig) |
|
|
|
|
|
|
|
|
|
producerInstance.Start() |
|
|
|
|
return &slsProducer{ |
|
|
|
|
return &Producer{ |
|
|
|
|
pr: producerInstance, |
|
|
|
|
opts: opt, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Close 程序结束时,必须调用该方法,不然可能导致部分日志丢失
|
|
|
|
|
func (s *slsProducer) Close() error { |
|
|
|
|
func (s *Producer) Close() error { |
|
|
|
|
return s.pr.Close(5000) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SendLog 发送普通日志
|
|
|
|
|
func (s *slsProducer) SendLog(topic, source string, log *sls.Log) error { |
|
|
|
|
func (s *Producer) SendLog(topic, source string, log *sls.Log) error { |
|
|
|
|
err := s.pr.SendLog(s.opts.project, s.opts.logstore, topic, source, log) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
@ -99,7 +99,7 @@ func (s *slsProducer) SendLog(topic, source string, log *sls.Log) error { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SendRequestLog 发送特定的请求日志,使用该方法时,不需要指定project和logstore
|
|
|
|
|
func (s *slsProducer) SendRequestLog(env enum.Env, req *Request) error { |
|
|
|
|
func (s *Producer) SendRequestLog(env enum.Env, req *Request) error { |
|
|
|
|
log := GenerateLog(req) |
|
|
|
|
|
|
|
|
|
err := s.pr.SendLog("bcpm-log", getLogStore(env), "request-go", req.RemoteAddr, log) |
|
|
|
|