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

[log] Use fields attached to logger #79

Closed
2 tasks done
at15 opened this issue Aug 7, 2018 · 1 comment
Closed
2 tasks done

[log] Use fields attached to logger #79

at15 opened this issue Aug 7, 2018 · 1 comment

Comments

@at15
Copy link
Member

at15 commented Aug 7, 2018

Currently, fields in logger are commented out, however, it's useful to inherit logger, like in logrus, there is WithField(s) to create new logger

type Logger struct {
	mu    sync.RWMutex
	h     Handler
	level Level
	// TODO: Fields in logger are never used, we are using DebugF to pass temporary fields
	// which does not allow inherit fields from parent logger
	//fields   Fields
	children map[string][]*Logger
	source   bool
	id       *Identity
}
func (s *S) init() {
   s.logger.AddStringField("f1", "v1")
}

func (s *S) Foo() {
     s.logger.Info(1) // pkg=f1 struct=S f1=v1
     fLogger := s.logger.WithFuncAuto() // add Func to field using runtime package, this have a much higher cost than given a string manually
     fLogger.Info(1) // pkg=f1 struct=S func=Foo f1=v1
     fLogger.WithField(dlog.Int("num", 2)).Info("mie") // pkg=f1 struct=S func=Foo f1=v1 num=2
}

There are some problems though

  • do we sort and merge duplicated fields, no
  • changes in the handlers, do we merge the slice of fields in logger, it's kind of a waste of space, no we pass to arguments,fields in logger are called cotnext, fields in log call site are called fields
@at15
Copy link
Member Author

at15 commented Nov 26, 2018

we didn't go with With syntax which either do a copy or create a new entry/event struct, we only have Add to add context in place, this problem should be solved after we figure out the correct way to deal with the tree of logger problem we created for ourselves ... #33 #78

logging fields attached to logger is implemented in #90

@at15 at15 closed this as completed Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant