Add logger to container and factory

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2014-10-30 22:08:28 +00:00 committed by Victor Marmol
parent d5b8418f75
commit 47b41a6f5d
5 changed files with 40 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import (
)
type CgroupManager interface {
String() string
GetPids(*cgroups.Cgroup) ([]int, error)
GetStats(*cgroups.Cgroup) (*cgroups.Stats, error)
}
@ -29,6 +30,10 @@ func (m *systemdCgroupManager) GetStats(config *cgroups.Cgroup) (*cgroups.Stats,
return systemd.GetStats(config)
}
func (m *systemdCgroupManager) String() string {
return "systemd"
}
type fsCgroupsManager struct {
}
@ -39,3 +44,7 @@ func (m *fsCgroupsManager) GetPids(config *cgroups.Cgroup) ([]int, error) {
func (m *fsCgroupsManager) GetStats(config *cgroups.Cgroup) (*cgroups.Stats, error) {
return fs.GetStats(config)
}
func (m *fsCgroupsManager) String() string {
return "fs"
}

View File

@ -2,7 +2,10 @@
package libcontainer
import "github.com/docker/libcontainer/network"
import (
"github.com/Sirupsen/logrus"
"github.com/docker/libcontainer/network"
)
type linuxContainer struct {
id string
@ -10,6 +13,7 @@ type linuxContainer struct {
config *Config
state *State
cgroupManager CgroupManager
logger *logrus.Logger
}
func (c *linuxContainer) ID() string {
@ -25,6 +29,7 @@ func (c *linuxContainer) RunState() (RunState, error) {
}
func (c *linuxContainer) Processes() ([]int, error) {
c.logger.Debug("fetch container processes")
pids, err := c.cgroupManager.GetPids(c.config.Cgroups)
if err != nil {
return nil, newGenericError(err, SystemError)
@ -33,6 +38,7 @@ func (c *linuxContainer) Processes() ([]int, error) {
}
func (c *linuxContainer) Stats() (*ContainerStats, error) {
c.logger.Debug("fetch container stats")
var (
err error
stats = &ContainerStats{}
@ -48,29 +54,36 @@ func (c *linuxContainer) Stats() (*ContainerStats, error) {
}
func (c *linuxContainer) StartProcess(config *ProcessConfig) (int, error) {
c.logger.Debug("start new container process")
panic("not implemented")
}
func (c *linuxContainer) Destroy() error {
c.logger.Debug("destroy container")
panic("not implemented")
}
func (c *linuxContainer) Pause() error {
c.logger.Debug("pause container")
panic("not implemented")
}
func (c *linuxContainer) Resume() error {
c.logger.Debug("resume container")
panic("not implemented")
}
func (c *linuxContainer) Signal(pid, signal int) error {
c.logger.Debugf("sending signal %d to pid %d", signal, pid)
panic("not implemented")
}
func (c *linuxContainer) Wait() (int, error) {
c.logger.Debug("wait container")
panic("not implemented")
}
func (c *linuxContainer) WaitProcess(pid int) (int, error) {
c.logger.Debugf("wait process %d", pid)
panic("not implemented")
}

View File

@ -6,6 +6,8 @@ import (
"encoding/json"
"os"
"path/filepath"
"github.com/Sirupsen/logrus"
)
const (
@ -14,13 +16,14 @@ const (
)
// New returns a linux based container factory based in the root directory.
func New(root string) (Factory, error) {
func New(root string, logger *logrus.Logger) (Factory, error) {
if err := os.MkdirAll(root, 0700); err != nil {
return nil, newGenericError(err, SystemError)
}
return &linuxFactory{
root: root,
root: root,
logger: logger,
}, nil
}
@ -28,6 +31,9 @@ func New(root string) (Factory, error) {
type linuxFactory struct {
// root is the root directory
root string
// standard logger for all packages
logger *logrus.Logger
}
func (l *linuxFactory) Create(id string, config *Config) (Container, error) {
@ -36,22 +42,27 @@ func (l *linuxFactory) Create(id string, config *Config) (Container, error) {
func (l *linuxFactory) Load(id string) (Container, error) {
containerRoot := filepath.Join(l.root, id)
l.logger.Debugf("loading container config from %s", containerRoot)
config, err := l.loadContainerConfig(containerRoot)
if err != nil {
return nil, err
}
l.logger.Debugf("loading container state from %s", containerRoot)
state, err := l.loadContainerState(containerRoot)
if err != nil {
return nil, err
}
cgroupManager := newCgroupsManager()
l.logger.Debugf("using %s as cgroup manager", cgroupManager)
return &linuxContainer{
id: id,
root: containerRoot,
config: config,
state: state,
cgroupManager: newCgroupsManager(),
cgroupManager: cgroupManager,
logger: l.logger,
}, nil
}

View File

@ -5,11 +5,13 @@ import (
"os"
"strings"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
var (
logPath = os.Getenv("log")
logger = logrus.New()
argvs = make(map[string]*rFunc)
)

View File

@ -16,7 +16,7 @@ var statsCommand = cli.Command{
}
func statsAction(context *cli.Context) {
factory, err := libcontainer.New(context.GlobalString("root"))
factory, err := libcontainer.New(context.GlobalString("root"), logger)
if err != nil {
log.Fatal(err)
}