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

writer: add CombineWriteSyncers #346

Merged
merged 4 commits into from
Mar 8, 2017
Merged

writer: add CombineWriteSyncers #346

merged 4 commits into from
Mar 8, 2017

Commits on Mar 8, 2017

  1. writer: add OpenWriteSyncers

    Allowing functions to take interfaces as parameters allows for better
    customization.
    
    For example, to have a writer that also counts the number of writes
    specifically made to its instance
    
    ```
    type MyWriter struct {
    	*os.File
    	logcount int
    }
    
    func (w *MyWriter) Write(data []byte) (int, error) {
    	w.logcount++
    	return w.File.Write(data)
    }
    
    func (w *MyWriter) Sync() error {
    	return w.File.Sync()
    }
    
    ...
    
    func main() {
    	f, err := os.Create(...)
    	if err != nil {
    		log.Fatal(err)
    	}
    	defer f.Close()
    
    	w := &MyWriter{f, 0}
    	ws, err := zap.OpenWriteSyncers(os.Stdout, zapcore.AddSync(w))
    	if err != nil {
    		log.Fatal(err)
    	}
    
    	core := zapcore.NewCore(
    		zapcore.NewConsoleEncoder(zap.NewProductionEncoderConfig()),
    		ws, zapcore.DebugLevel)
    
    	logger := zap.New(core)
    
    	...
    
    	fmt.Printf("logged %v times to MyWriter", w.logcount)
    }
    ```
    suyash committed Mar 8, 2017
    Configuration menu
    Copy the full SHA
    5cd8317 View commit details
    Browse the repository at this point in the history
  2. rename to CombineWriteSyncers

    suyash committed Mar 8, 2017
    Configuration menu
    Copy the full SHA
    a592c8c View commit details
    Browse the repository at this point in the history
  3. fix Test Function name

    suyash committed Mar 8, 2017
    Configuration menu
    Copy the full SHA
    88322a5 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    59545c4 View commit details
    Browse the repository at this point in the history