-
Notifications
You must be signed in to change notification settings - Fork 0
/
sypl.go
739 lines (582 loc) · 20.4 KB
/
sypl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
// Copyright 2021 The sypl Authors. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package sypl
import (
"bufio"
"errors"
"fmt"
"log"
"os"
"strings"
"github.com/thalesfsp/sypl/debug"
"github.com/thalesfsp/sypl/fields"
"github.com/thalesfsp/sypl/flag"
"github.com/thalesfsp/sypl/formatter"
"github.com/thalesfsp/sypl/level"
"github.com/thalesfsp/sypl/message"
"github.com/thalesfsp/sypl/options"
"github.com/thalesfsp/sypl/output"
"github.com/thalesfsp/sypl/processor"
"github.com/thalesfsp/sypl/shared"
"github.com/thalesfsp/sypl/status"
"golang.org/x/sync/errgroup"
)
// MessageToOutput defines a `Message` to printed at the specified `Level`, and
// to the specified `Output`.
type MessageToOutput struct {
// Content to be printed.
Content string
// Level of the message.
Level level.Level
// OutputName name of the output.
OutputName string
}
// Sypl logger definition.
type Sypl struct {
// Name returns the logger name.
//
// Note: Exposed to deal with https://github.com/golang/go/issues/5819.
Name string
// NOTE: Changes here may reflect in the `New(name string)` method (Child).
defaultIoWriterLevel level.Level
fields fields.Fields
outputs []output.IOutput
status status.Status
}
// String interface implementation.
func (sypl Sypl) String() string {
return sypl.Name
}
//////
// IMeta interface implementation.
//////
// GetName returns the sypl Name.
func (sypl *Sypl) GetName() string {
return sypl.Name
}
// SetName sets the sypl Name.
func (sypl *Sypl) SetName(name string) {
sypl.Name = name
}
// GetStatus returns the sypl status.
func (sypl *Sypl) GetStatus() status.Status {
return sypl.status
}
// SetStatus sets the sypl status.
func (sypl *Sypl) SetStatus(s status.Status) {
sypl.status = s
}
// GetDefaultIoWriterLevel returns the sypl status.
func (sypl *Sypl) GetDefaultIoWriterLevel() level.Level {
return sypl.defaultIoWriterLevel
}
// SetDefaultIoWriterLevel sets the default io.Writer level.
func (sypl *Sypl) SetDefaultIoWriterLevel(l level.Level) {
sypl.defaultIoWriterLevel = l
}
//////
// Writer interface implementation.
//////
// Writer implements the io.Writer interface. Message level will be the one set
// via `SetIoWriterLevel`, default is `none`. It always returns `0, nil`.
//
// NOTE: This is a convenient method, if it doesn't fits your need, just
// implement the way you need, as you would do.
func (sypl *Sypl) Write(p []byte) (int, error) {
sypl.process(message.New(sypl.defaultIoWriterLevel, string(p)))
return 0, nil
}
//////
// IBasePrinter interface implementation.
//////
// PrintMessage prints messages. It's a powerful option because it gives
// full-control over the message. Use `New` to create the message.
// it gives full-control over the message. Use `New` to create the
// message.
func (sypl *Sypl) PrintMessage(messages ...message.IMessage) ISypl {
sypl.process(messages...)
return sypl
}
// PrintWithOptions is a more flexible way of printing, allowing to specify
// a few message's options. For full-control over the message is possible
// via `PrintMessage`.
func (sypl *Sypl) PrintWithOptions(o *options.Options, l level.Level, args ...interface{}) ISypl {
m := message.New(l, fmt.Sprint(args...))
sypl.PrintMessage(mergeOptions(m, o))
return sypl
}
// PrintfWithOptions prints according with the specified format. It's a more
// flexible way of printing, allowing to specify a few message's options.
// For full-control over the message is possible via `PrintMessage`.
func (sypl *Sypl) PrintfWithOptions(o *options.Options, l level.Level, format string, args ...interface{}) ISypl {
m := message.New(l, fmt.Sprintf(format, args...))
sypl.PrintMessage(mergeOptions(m, o))
return sypl
}
// PrintlnfWithOptions prints according with the specified format, also adding
// a new line to the end. It's a more flexible way of printing, allowing to
// specify a few message's options. For full-control over the message is
// possible via `PrintMessage`.
func (sypl *Sypl) PrintlnfWithOptions(o *options.Options, l level.Level, format string, args ...interface{}) ISypl {
m := message.New(l, fmt.Sprintf(format+"\n", args...))
sypl.PrintMessage(mergeOptions(m, o))
return sypl
}
// PrintlnWithOptions prints, also adding a new line to the end. It's a more
// flexible way of printing, allowing to specify a few message's options.
// For full-control over the message is possible via `PrintMessage`.
func (sypl *Sypl) PrintlnWithOptions(o *options.Options, l level.Level, args ...interface{}) ISypl {
m := message.New(l, fmt.Sprintln(args...))
sypl.PrintMessage(mergeOptions(m, o))
return sypl
}
//////
// IBasicPrinter interface implementation.
//////
// Print just prints.
func (sypl *Sypl) Print(l level.Level, args ...interface{}) ISypl {
return sypl.PrintWithOptions(options.New(), l, args...)
}
// Printf prints according with the specified format.
func (sypl *Sypl) Printf(l level.Level, format string, args ...interface{}) ISypl {
return sypl.PrintfWithOptions(options.New(), l, format, args...)
}
// Printlnf prints according with the specified format, also adding a new line
// to the end.
func (sypl *Sypl) Printlnf(l level.Level, format string, args ...interface{}) ISypl {
return sypl.PrintlnfWithOptions(options.New(), l, format, args...)
}
// Println prints, also adding a new line to the end.
func (sypl *Sypl) Println(l level.Level, args ...interface{}) ISypl {
return sypl.PrintlnWithOptions(options.New(), l, args...)
}
//////
// IConvenientPrinter interface implementation.
//////
// PrintPretty prints data structures as JSON text.
//
// Notes:
// - Only exported fields of the data structure will be printed.
// - Message isn't processed.
func (sypl *Sypl) PrintPretty(l level.Level, data interface{}) ISypl {
msg := message.New(l, fmt.Sprint(shared.Prettify(data)))
msg.SetFlag(flag.Skip)
return sypl.PrintMessage(msg)
}
// PrintlnPretty prints data structures as JSON text, also adding a new line
// to the end.
//
// Notes:
// - Only exported fields of the data structure will be printed.
// - Message isn't processed.
func (sypl *Sypl) PrintlnPretty(l level.Level, data interface{}) ISypl {
msg := message.New(l, fmt.Sprintln(shared.Prettify(data)))
msg.SetFlag(flag.Skip)
return sypl.PrintMessage(msg)
}
// PrintMessagesToOutputs allows you to concurrently print messages, each one,
// at the specified level and to the specified output.
//
// Note: If the named output doesn't exits, the message will not be printed.
func (sypl *Sypl) PrintMessagesToOutputs(messagesToOutputs ...MessageToOutput) ISypl {
messages := []message.IMessage{}
for _, mto := range messagesToOutputs {
m := message.New(mto.Level, mto.Content)
m.SetOutputsNames([]string{mto.OutputName})
messages = append(messages, m)
}
sypl.process(messages...)
return sypl
}
// PrintMessagesToOutputsWithOptions allows you to concurrently print messages,
// each one, at the specified level and to the specified output, with options.
//
// Note: If the named output doesn't exits, the message will not be printed.
func (sypl *Sypl) PrintMessagesToOutputsWithOptions(
o *options.Options,
messagesToOutputs ...MessageToOutput,
) ISypl {
messages := []message.IMessage{}
for _, mto := range messagesToOutputs {
m := message.New(mto.Level, mto.Content)
m.SetOutputsNames([]string{mto.OutputName})
messages = append(messages, mergeOptions(m, o))
}
sypl.process(messages...)
return sypl
}
// PrintNewLine prints a new line. It always print, independent of the level,
// and without any processing.
func (sypl *Sypl) PrintNewLine() ISypl {
m := message.New(level.Info, "\n")
m.SetFlag(flag.SkipAndForce)
sypl.process(m)
return sypl
}
//////
// ILeveledPrinter interface implementation.
//////
// Fatal prints, and exit with os.Exit(1).
func (sypl *Sypl) Fatal(args ...interface{}) ISypl {
return sypl.Print(level.Fatal, args...)
}
// Fatalf prints according with the format, and exit with os.Exit(1).
func (sypl *Sypl) Fatalf(format string, args ...interface{}) ISypl {
return sypl.Printf(level.Fatal, format, args...)
}
// Fatallnf prints according with the format, also adding a new line to the
// end, and exit with os.Exit(1).
func (sypl *Sypl) Fatallnf(format string, args ...interface{}) ISypl {
return sypl.Printlnf(level.Fatal, format, args...)
}
// Fatalln prints, also adding a new line and the end, and exit with os.Exit(1).
func (sypl *Sypl) Fatalln(args ...interface{}) ISypl {
return sypl.Println(level.Fatal, args...)
}
// Error prints @ the Error level.
func (sypl *Sypl) Error(args ...interface{}) ISypl {
return sypl.Print(level.Error, args...)
}
// Errorf prints according with the format @ the Error level.
func (sypl *Sypl) Errorf(format string, args ...interface{}) ISypl {
return sypl.Printf(level.Error, format, args...)
}
// Errorlnf prints according with the format @ the Error level, also adding
// a new line to the end.
func (sypl *Sypl) Errorlnf(format string, args ...interface{}) ISypl {
return sypl.Printlnf(level.Error, format, args...)
}
// Errorln prints, also adding a new line to the end @ the Error level.
func (sypl *Sypl) Errorln(args ...interface{}) ISypl {
return sypl.Println(level.Error, args...)
}
// Serror prints like Error, and returns an error with the non-processed
// content.
func (sypl *Sypl) Serror(args ...interface{}) error {
sypl.Print(level.Error, args...)
return errors.New(fmt.Sprint(args...))
}
// Serrorf prints like Errorf, and returns an error with the non-processed
// content.
func (sypl *Sypl) Serrorf(format string, args ...interface{}) error {
sypl.Printf(level.Error, format, args...)
return fmt.Errorf(format, args...)
}
// Serrorlnf prints like Errorlnf, and returns an error with the
// non-processed content.
func (sypl *Sypl) Serrorlnf(format string, args ...interface{}) error {
sypl.Printlnf(level.Error, format, args...)
return fmt.Errorf(format+"\n", args...)
}
// Serrorln prints like Errorln, and returns an error with the non-processed
// content.
func (sypl *Sypl) Serrorln(args ...interface{}) error {
sypl.Println(level.Error, args...)
return errors.New(fmt.Sprintln(args...))
}
// Info prints @ the Info level.
func (sypl *Sypl) Info(args ...interface{}) ISypl {
return sypl.Print(level.Info, args...)
}
// Infof prints according with the specified format @ the Info level.
func (sypl *Sypl) Infof(format string, args ...interface{}) ISypl {
return sypl.Printf(level.Info, format, args...)
}
// Infolnf prints according with the specified format @ the Info level, also
// adding a new line to the end.
func (sypl *Sypl) Infolnf(format string, args ...interface{}) ISypl {
return sypl.Printlnf(level.Info, format, args...)
}
// Infoln prints, also adding a new line to the end @ the Info level.
func (sypl *Sypl) Infoln(args ...interface{}) ISypl {
return sypl.Println(level.Info, args...)
}
// Warn prints @ the Warn level.
func (sypl *Sypl) Warn(args ...interface{}) ISypl {
return sypl.Print(level.Warn, args...)
}
// Warnf prints according with the specified format @ the Warn level.
func (sypl *Sypl) Warnf(format string, args ...interface{}) ISypl {
return sypl.Printf(level.Warn, format, args...)
}
// Warnlnf prints according with the specified format @ the Warn level, also
// adding a new line to the end.
func (sypl *Sypl) Warnlnf(format string, args ...interface{}) ISypl {
return sypl.Printlnf(level.Warn, format, args...)
}
// Warnln prints, also adding a new line to the end @ the Warn level.
func (sypl *Sypl) Warnln(args ...interface{}) ISypl {
return sypl.Println(level.Warn, args...)
}
// Debug prints @ the Debug level.
func (sypl *Sypl) Debug(args ...interface{}) ISypl {
return sypl.Print(level.Debug, args...)
}
// Debugf prints according with the specified format @ the Debug level.
func (sypl *Sypl) Debugf(format string, args ...interface{}) ISypl {
return sypl.Printf(level.Debug, format, args...)
}
// Debuglnf prints according with the specified format @ the Debug level,
// also adding a new line to the end.
func (sypl *Sypl) Debuglnf(format string, args ...interface{}) ISypl {
return sypl.Printlnf(level.Debug, format, args...)
}
// Debugln prints, also adding a new line to the end @ the Debug level.
func (sypl *Sypl) Debugln(args ...interface{}) ISypl {
return sypl.Println(level.Debug, args...)
}
// Trace prints @ the Trace level.
func (sypl *Sypl) Trace(args ...interface{}) ISypl {
return sypl.Print(level.Trace, args...)
}
// Tracef prints according with the specified format @ the Trace level.
func (sypl *Sypl) Tracef(format string, args ...interface{}) ISypl {
return sypl.Printf(level.Trace, format, args...)
}
// Tracelnf prints according with the specified format @ the Trace level,
// also adding a new line to the end.
func (sypl *Sypl) Tracelnf(format string, args ...interface{}) ISypl {
return sypl.Printlnf(level.Trace, format, args...)
}
// Traceln prints, also adding a new line to the end @ the Trace level.
func (sypl *Sypl) Traceln(args ...interface{}) ISypl {
return sypl.Println(level.Trace, args...)
}
//////
// ISypl interface implementation.
//////
// Breakpoint will stop execution waiting the user press "/n" ("enter") to
// continue. It helps users doing log-to-console debug strategy. A message
// with the breakpoint `name`, and PID of the process will be printed using
// the `debug` level. Arbitrary `data` can optionally be set - if set, it'll
// be printed. Errors are printed using the `error` level. Set logging level
// to `trace` for more.
func (sypl *Sypl) Breakpoint(name string, data ...interface{}) ISypl {
breakpointName := fmt.Sprintf(`Breakpoint: %s. PID: %d`, name, os.Getpid())
if data != nil {
breakpointName = fmt.Sprintf("%s. Data:", breakpointName)
for _, d := range data {
breakpointName = fmt.Sprintf("%s %+v,", breakpointName, d)
}
breakpointName = strings.TrimSuffix(breakpointName, ",")
}
sypl.Debugf("%s. Press enter to continue...", breakpointName)
reader := bufio.NewReader(os.Stdin)
if _, err := reader.ReadString('\n'); err != nil {
sypl.Errorlnf("%s. Failed to read input: %s", breakpointName, err)
} else {
sypl.Traceln("Resuming")
}
return sypl
}
// GetFields returns the structured fields.
func (sypl *Sypl) GetFields() fields.Fields {
return sypl.fields
}
// SetFields sets the structured fields.
func (sypl *Sypl) SetFields(fields fields.Fields) ISypl {
sypl.fields = fields
return sypl
}
// GetMaxLevel returns the `maxLevel` of all outputs.
func (sypl *Sypl) GetMaxLevel() map[string]level.Level {
levelMap := map[string]level.Level{}
for _, output := range sypl.GetOutputs() {
levelMap[output.GetName()] = output.GetMaxLevel()
}
return levelMap
}
// SetMaxLevel sets the `maxLevel` of all outputs.
func (sypl *Sypl) SetMaxLevel(l level.Level) ISypl {
for _, output := range sypl.GetOutputs() {
output.SetMaxLevel(l)
}
return sypl
}
// AddOutputs adds one or more outputs.
func (sypl *Sypl) AddOutputs(outputs ...output.IOutput) ISypl {
sypl.outputs = append(sypl.outputs, outputs...)
return sypl
}
// GetOutput returns the registered output by its name. If not found, will be
// nil.
func (sypl *Sypl) GetOutput(name string) output.IOutput {
for _, o := range sypl.outputs {
if strings.EqualFold(o.GetName(), name) {
return o
}
}
return nil
}
// SetOutputs sets one or more outputs. Use to update output(s).
func (sypl *Sypl) SetOutputs(outputs ...output.IOutput) ISypl {
for _, output := range outputs {
for i, o := range sypl.outputs {
if strings.EqualFold(o.GetName(), output.GetName()) {
sypl.outputs[i] = output
}
}
}
return sypl
}
// GetOutputs returns registered outputs.
func (sypl *Sypl) GetOutputs() []output.IOutput {
return sypl.outputs
}
// GetOutputsNames returns the names of the registered outputs.
func (sypl *Sypl) GetOutputsNames() []string {
outputsNames := []string{}
for _, output := range sypl.outputs {
outputsNames = append(outputsNames, output.GetName())
}
return outputsNames
}
// New creates a child logger. The child logger is an accurate, efficient and
// shallow copy of the parent logger. Changes to internals, such as the state of
// outputs, and processors, are reflected cross all other loggers.
func (sypl *Sypl) New(name string) *Sypl {
s := New(name, sypl.outputs...)
s.defaultIoWriterLevel = sypl.defaultIoWriterLevel
s.fields = sypl.fields
s.status = sypl.status
return s
}
// Process messages, per output, and process accordingly.
func (sypl *Sypl) process(messages ...message.IMessage) {
if sypl == nil {
log.Fatalf("%s %s", shared.ErrorPrefix, ErrSyplNotInitialized)
}
shouldExit := false
g := new(errgroup.Group)
for _, m := range messages {
// https://golang.org/doc/faq#closures_and_goroutines
m := m
g.Go(func() error {
// Do nothing if message as no context, or flagged with `SkipAndMute`.
if m.GetContent().GetOriginal() == "" &&
m.GetFlag() == flag.SkipAndMute {
return nil
}
// Should allows to filter logging by components names.
syplFilterEnvVar := os.Getenv(shared.FilterEnvVar)
if syplFilterEnvVar != "" &&
!strings.Contains(syplFilterEnvVar, sypl.GetName()) {
return nil
}
// Should allows to specify `Output`(s).
outputsNames := sypl.GetOutputsNames()
if len(m.GetOutputsNames()) > 0 {
outputsNames = m.GetOutputsNames()
}
m.SetOutputsNames(outputsNames)
// Should allows to set global fields.
// Per-message fields should have precedence.
finalFields := fields.Fields{}
finalFields = fields.Copy(sypl.GetFields(), finalFields)
finalFields = fields.Copy(m.GetFields(), finalFields)
m.SetFields(finalFields)
sypl.processOutputs(m, strings.Join(outputsNames, ","))
if m.GetLevel() == level.Fatal {
shouldExit = true
}
return nil
})
}
_ = g.Wait()
// Should exit if `level` is `Fatal`.
if shouldExit {
os.Exit(1)
}
}
//////
// Helpers.
//////
// Merge options into message.
//
// Notes:
// - Changes in the `Message` or `Options` data structure may reflects here.
// - Could use something like the `Copier` package, but that's going to cause a
// data race, because `Output`s are processed concurrently.
func mergeOptions(m message.IMessage, o *options.Options) message.IMessage {
if o.Fields != nil {
m.SetFields(o.Fields)
}
if o.Flag != flag.None {
m.SetFlag(o.Flag)
}
if len(o.OutputsNames) > 0 {
m.SetOutputsNames(o.OutputsNames)
}
if len(o.ProcessorsNames) > 0 {
m.SetProcessorsNames(o.ProcessorsNames)
}
if len(o.Tags) > 0 {
// Merge `options.Tags`.
m.GetMessage().Tags = o.Tags
// Adds tags to `message.tags`.
m.AddTags(o.Tags...)
}
return m
}
// Outputs logic of the Process method.
func (sypl *Sypl) processOutputs(m message.IMessage, outputsNames string) {
g := new(errgroup.Group)
for _, o := range sypl.outputs {
// https://golang.org/doc/faq#closures_and_goroutines
o := o
m := m
// Message is isolated per `Output`.
msg := message.Copy(m)
// Should only use enabled Outputs, and named (listed) ones.
if o.GetStatus() == status.Enabled && strings.Contains(outputsNames, o.GetName()) {
msg.SetComponentName(sypl.GetName())
msg.SetOutputName(o.GetName())
// Debug capability.
// Should only run if Debug env var is set.
if os.Getenv(shared.DebugEnvVar) != "" {
msg.SetDebugEnvVarRegexes(
debug.New(msg.GetComponentName(), msg.GetOutputName()),
)
}
g.Go(func() error {
return o.Write(msg)
})
}
}
_ = g.Wait()
}
//////
// Factory.
//////
// New is the Sypl factory.
func New(name string, outputs ...output.IOutput) *Sypl {
return &Sypl{
Name: name,
defaultIoWriterLevel: level.None,
fields: fields.Fields{},
outputs: outputs,
status: status.Enabled,
}
}
// NewDefault creates a logger that covers most of all needs:
// - Writes message to `stdout` @ the specified `maxLevel`
// - Writes error messages only to `stderr`
// - Default io.Writer level is `none`. Explicitly change that using
// `SetDefaultIoWriterLevel` to suit your need.
//
// NOTE: `processors` are applied to both outputs.
func NewDefault(name string, maxLevel level.Level, processors ...processor.IProcessor) *Sypl {
consoleProcessors := processors
consoleProcessors = append(consoleProcessors, processor.MuteBasedOnLevel(level.Fatal, level.Error))
return &Sypl{
Name: name,
defaultIoWriterLevel: level.None,
fields: fields.Fields{},
outputs: []output.IOutput{
output.Console(maxLevel, consoleProcessors...).SetFormatter(formatter.Text()),
output.StdErr(processors...).SetFormatter(formatter.Text()),
},
status: status.Enabled,
}
}