@@ -65,6 +65,24 @@ func NewBeatForReceiver(settings instance.Settings, receiverConfig map[string]an
6565 ucfg .VarExp ,
6666 }
6767
68+ err = setLogger (b , receiverConfig , core )
69+ if err != nil {
70+ return nil , fmt .Errorf ("error configuring beats logger: %w" , err )
71+ }
72+
73+ // extracting it here for ease of use
74+ logger := b .Info .Logger
75+
76+ // if output is set and if output is not otelconsumer, inform users
77+ if receiverConfig ["output" ] != nil && receiverConfig ["output" ].(map [string ]any )["otelconsumer" ] == nil { //nolint: errcheck // output will always be of map type
78+ logger .Debugf ("configured output does not work with beatreceiver, please use appropriate exporter instead" )
79+ }
80+
81+ // all beatreceivers will use otelconsumer output by default
82+ receiverConfig ["output" ] = map [string ]any {
83+ "otelconsumer" : map [string ]any {},
84+ }
85+
6886 tmp , err := ucfg .NewFrom (receiverConfig , cfOpts ... )
6987 if err != nil {
7088 return nil , fmt .Errorf ("error converting receiver config to ucfg: %w" , err )
@@ -113,37 +131,12 @@ func NewBeatForReceiver(settings instance.Settings, receiverConfig map[string]an
113131 return nil , fmt .Errorf ("error unpacking config data: %w" , err )
114132 }
115133
116- logpConfig := logp.Config {}
117- logpConfig .AddCaller = true
118- logpConfig .Beat = b .Info .Beat
119- logpConfig .Files .MaxSize = 1
120-
121- if b .Config .Logging == nil {
122- b .Config .Logging = config .NewConfig ()
123- }
124-
125- if err := b .Config .Logging .Unpack (& logpConfig ); err != nil {
126- return nil , fmt .Errorf ("error unpacking beats logging config: %w\n %v" , err , b .Config .Logging )
127- }
128-
129- b .Info .Logger , err = logp .ConfigureWithCoreLocal (logpConfig , core )
130- if err != nil {
131- return nil , fmt .Errorf ("error configuring beats logp: %w" , err )
132- }
133-
134- // extracting it here for ease of use
135- logger := b .Info .Logger
136-
137134 instrumentation , err := instrumentation .New (cfg , b .Info .Beat , b .Info .Version , logger )
138135 if err != nil {
139136 return nil , fmt .Errorf ("error setting up instrumentation: %w" , err )
140137 }
141138 b .Instrumentation = instrumentation
142139
143- if err := instance .PromoteOutputQueueSettings (b ); err != nil {
144- return nil , fmt .Errorf ("could not promote output queue settings: %w" , err )
145- }
146-
147140 if err := features .UpdateFromConfig (b .RawConfig ); err != nil {
148141 return nil , fmt .Errorf ("could not parse features: %w" , err )
149142 }
@@ -246,17 +239,6 @@ func NewBeatForReceiver(settings instance.Settings, receiverConfig map[string]an
246239 }
247240 b .SetProcessors (processors )
248241
249- // This should be replaced with static config for otel consumer
250- // but need to figure out if we want the Queue settings from here.
251- outputEnabled := b .Config .Output .IsSet () && b .Config .Output .Config ().Enabled ()
252- if ! outputEnabled {
253- if b .Manager .Enabled () {
254- logger .Info ("Output is configured through Central Management" )
255- } else {
256- return nil , fmt .Errorf ("no outputs are defined, please define one under the output section" )
257- }
258- }
259-
260242 reg := b .Monitoring .StatsRegistry ().GetOrCreateRegistry ("libbeat" )
261243
262244 monitors := pipeline.Monitors {
@@ -283,3 +265,31 @@ func NewBeatForReceiver(settings instance.Settings, receiverConfig map[string]an
283265
284266 return b , nil
285267}
268+
269+ // setLogger configures a logp logger and sets it on b.Info.Logger
270+ func setLogger (b * instance.Beat , receiverConfig map [string ]any , core zapcore.Core ) error {
271+
272+ var err error
273+ logpConfig := logp.Config {}
274+ logpConfig .AddCaller = true
275+ logpConfig .Beat = b .Info .Beat
276+ logpConfig .Files .MaxSize = 1
277+
278+ var logCfg * config.C
279+ if _ , ok := receiverConfig ["logging" ]; ! ok {
280+ logCfg = config .NewConfig ()
281+ } else {
282+ logCfg = config .MustNewConfigFrom (receiverConfig ["logging" ])
283+ }
284+
285+ if err := logCfg .Unpack (& logpConfig ); err != nil {
286+ return fmt .Errorf ("error unpacking beats logging config: %w\n %v" , err , b .Config .Logging )
287+ }
288+
289+ b .Info .Logger , err = logp .ConfigureWithCoreLocal (logpConfig , core )
290+ if err != nil {
291+ return fmt .Errorf ("error configuring beats logp: %w" , err )
292+ }
293+
294+ return nil
295+ }
0 commit comments