github.com/ilhicas/nomad@v0.11.8/drivers/docker/docklog/z_docker_logger_cmd.go (about)

     1  package docklog
     2  
     3  import (
     4  	"os"
     5  
     6  	log "github.com/hashicorp/go-hclog"
     7  	plugin "github.com/hashicorp/go-plugin"
     8  	"github.com/hashicorp/nomad/plugins/base"
     9  )
    10  
    11  // Install a plugin cli handler to ease working with tests
    12  // and external plugins.
    13  // This init() must be initialized last in package required by the child plugin
    14  // process. It's recommended to avoid any other `init()` or inline any necessary calls
    15  // here. See eeaa95d commit message for more details.
    16  func init() {
    17  	if len(os.Args) > 1 && os.Args[1] == PluginName {
    18  		logger := log.New(&log.LoggerOptions{
    19  			Level:      log.Trace,
    20  			JSONFormat: true,
    21  			Name:       PluginName,
    22  		})
    23  
    24  		plugin.Serve(&plugin.ServeConfig{
    25  			HandshakeConfig: base.Handshake,
    26  			Plugins: map[string]plugin.Plugin{
    27  				PluginName: NewPlugin(NewDockerLogger(logger)),
    28  			},
    29  			GRPCServer: plugin.DefaultGRPCServer,
    30  			Logger:     logger,
    31  		})
    32  		os.Exit(0)
    33  	}
    34  }