github.com/mheon/docker@v0.11.2-0.20150922122814-44f47903a831/daemon/logger/context.go (about)

     1  package logger
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strings"
     7  	"time"
     8  )
     9  
    10  // Context provides enough information for a logging driver to do its function.
    11  type Context struct {
    12  	Config              map[string]string
    13  	ContainerID         string
    14  	ContainerName       string
    15  	ContainerEntrypoint string
    16  	ContainerArgs       []string
    17  	ContainerImageID    string
    18  	ContainerImageName  string
    19  	ContainerCreated    time.Time
    20  	LogPath             string
    21  }
    22  
    23  // Hostname returns the hostname from the underlying OS.
    24  func (ctx *Context) Hostname() (string, error) {
    25  	hostname, err := os.Hostname()
    26  	if err != nil {
    27  		return "", fmt.Errorf("logger: can not resolve hostname: %v", err)
    28  	}
    29  	return hostname, nil
    30  }
    31  
    32  // Command returns the command that the container being logged was
    33  // started with. The Entrypoint is prepended to the container
    34  // arguments.
    35  func (ctx *Context) Command() string {
    36  	terms := []string{ctx.ContainerEntrypoint}
    37  	for _, arg := range ctx.ContainerArgs {
    38  		terms = append(terms, arg)
    39  	}
    40  	command := strings.Join(terms, " ")
    41  	return command
    42  }
    43  
    44  // ID Returns the Container ID shortened to 12 characters.
    45  func (ctx *Context) ID() string {
    46  	return ctx.ContainerID[:12]
    47  }
    48  
    49  // FullID is an alias of ContainerID.
    50  func (ctx *Context) FullID() string {
    51  	return ctx.ContainerID
    52  }
    53  
    54  // Name returns the ContainerName without a preceding '/'.
    55  func (ctx *Context) Name() string {
    56  	return ctx.ContainerName[1:]
    57  }
    58  
    59  // ImageID returns the ContainerImageID shortened to 12 characters.
    60  func (ctx *Context) ImageID() string {
    61  	return ctx.ContainerImageID[:12]
    62  }
    63  
    64  // ImageFullID is an alias of ContainerID.
    65  func (ctx *Context) ImageFullID() string {
    66  	return ctx.ContainerImageID
    67  }
    68  
    69  // ImageName is an alias of ContainerImageName
    70  func (ctx *Context) ImageName() string {
    71  	return ctx.ContainerImageName
    72  }