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