title: How to log to stdout or stderr based on log level using uber-go/zap?
body: <p>I am trying to set up logging using this package <a href="https://github.com/uber-go/zap" rel="nofollow noreferrer"><code>github.com/uber-go/zap</code></a>.
  I need to write:</p>
  <ul>
  <li>Info logs to stdout</li>
  <li>Error and Fatal logs to stderr</li>
  </ul>
  <p>I tried to do this by setting up and building <code>zap.Config</code> like this:</p>
  <pre class="lang-golang prettyprint-override"><code>    cfg = &amp;zap.Config{
          Encoding:         &quot;json&quot;,
          Level:            zap.NewAtomicLevelAt(zapcore.DebugLevel),
          OutputPaths:      []string{&quot;stdout&quot;},
          ErrorOutputPaths: []string{&quot;stderr&quot;},
          EncoderConfig: zapcore.EncoderConfig{
              MessageKey: &quot;message&quot;,
  
              LevelKey:    &quot;level&quot;,
              EncodeLevel: zapcore.CapitalLevelEncoder,
  
              TimeKey:    &quot;time&quot;,
              EncodeTime: zapcore.ISO8601TimeEncoder,
  
              CallerKey:    &quot;caller&quot;,
              EncodeCaller: zapcore.ShortCallerEncoder,
  
              EncodeDuration: zapcore.MillisDurationEncoder,
          },
      }
  </code></pre>
  <p>Also I tried this way:</p>
  <pre><code>cfg = zap.NewProductionConfig()
      cfg.OutputPaths = []string{&quot;stdout&quot;}
      logger, err = cfg.Build(zap.AddCaller(), zap.AddCallerSkip(1))
  </code></pre>
  <p>But all logs are written to either stdout <strong>or</strong> stderr. How can I separate it?</p>