title: Better way of using logger in Golang?
body: <p>I am initialising a logger in my main application something like this.</p>
  <pre><code>----------main.go----------
  package main
  type AppServer struct {
      router *gin.Engine
      server *http.Server
      logger zerolog.Logger
  }
  
  func (app *AppServer) Init(pm zerolog.Logger) error {
     
      ........
      app.logger = pm
      //Here i am sending this logger to the service package
      services.Service.Init(pm)
      ..........
      return nil
  }
  </code></pre>
  <p>Now i am saving this in a struct in my service.go file like this..</p>
  <pre><code>----------service.go----------
  
  package services
  
  ................
  
  var (
      Service serviceInterface = &amp;service{}
  )
  
  type service struct {
      pm   zerolog.Logger
      path string
  }
  
  type serviceInterface interface {
      Init(zerolog.Logger) error
      p_man() (zerolog.Logger, error)
  }
  //This is called from main application to store that logger in this struct
  func (s *service) Init(pm zerolog.Logger) error {
      s.pm = pm
      return nil
  }
  //Returningg the saved logger from struct
  func (s *service) p_man() (zerolog.Logger, error) {
      
      return s.pm, nil
  }
  </code></pre>
  <p>Now the first option i have is that, i can use it in other files with same package=services directly e.g.</p>
  <pre><code>----------1st option example1.go----------
  package services
  
  func (s *service) first() error {
      fmt.Println(s.pm)
      return nil
  }
  </code></pre>
  <p>or using the function param_manager</p>
  <pre><code>----------2nd option example1.go----------
  package services
  
  func (s *service) 2nd() error {
      a,_:= Service.p_man()
      fmt.Println(a)
      return nil
  }
  </code></pre>
  <p>I am confused about which is the right or better way of doing this? i would like to use the same logger in some other packages as well. So far i have a service package with different interfaces and if i use the 1st one then i have to define only one interface for all the functions and use the logger. And then for other packages i again have to init that in main.go for each package. Is the 2nd way better then 1st one? as i can import the package in other packages and use the function directly to get the logger?</p>