Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
logger: Switch to system log
Browse files Browse the repository at this point in the history
Remove the global logfile feature and use the system log
(syslog/journald) instead. This is for consistency with the other
components, allowing for easier overall analysis.

Fixes #788.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Nov 7, 2017
1 parent 5551a28 commit f98e619
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 606 deletions.
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ PROXYCMD := cc-proxy
PROXYURL := unix://$(PKGRUNDIR)/proxy.sock
PROXYPATH := $(PKGLIBEXECDIR)/$(PROXYCMD)

GLOBALLOGPATH := $(PKGLIBDIR)/runtime/runtime.log

# Default number of vCPUs
DEFVCPUS := 1
# Default memory size in MiB
Expand Down Expand Up @@ -155,7 +153,6 @@ USER_VARS += DESTCONFIG
USER_VARS += DESTDIR
USER_VARS += DESTSYSCONFIG
USER_VARS += DESTTARGET
USER_VARS += GLOBALLOGPATH
USER_VARS += IMAGEPATH
USER_VARS += MACHINETYPE
USER_VARS += KERNELPATH
Expand Down Expand Up @@ -295,7 +292,6 @@ $(GENERATED_FILES): %: %.in Makefile VERSION
-e "s|@QEMUPATH@|$(QEMUPATH)|g" \
-e "s|@MACHINETYPE@|$(MACHINETYPE)|g" \
-e "s|@SHIMPATH@|$(SHIMPATH)|g" \
-e "s|@GLOBALLOGPATH@|$(GLOBALLOGPATH)|g" \
-e "s|@DEFVCPUS@|$(DEFVCPUS)|g" \
-e "s|@DEFMEMSZ@|$(DEFMEMSZ)|g" \
-e "s|@DEFDISABLEBLOCK@|$(DEFDISABLEBLOCK)|g" \
Expand Down
37 changes: 6 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* [Community](#community)
* [Configuration](#configuration)
* [Debugging](#debugging)
* [Global logfile](#global-logfile)
* [Enabling debug for various components](#enabling-debug-for-various-components)
* [Limitations](#limitations)
* [Home Page](#home-page)
Expand Down Expand Up @@ -82,41 +81,17 @@ $ cc-runtime cc-env

## Debugging

### Global logfile
The runtime provides `--log=` and `--log-format=` options. However, it can
also be configured to log to the system log (syslog or `journald`) such that
all log data is sent to both the specified logfile and the system log. The
latter is useful as it is independent of the lifecycle of each container.

To provide a persistent log of all container activity on the system, the runtime
offers a global logging facility. By default, this feature is disabled
but can be enabled with a simple change to the [configuration](#Configuration) file.

First, to determine the configuration file path for your host run:

```bash
$ cc-runtime cc-env | grep -A 1 Runtime.Config
```

To enable the global log:

```bash
$ sudo sed -i -e 's/^#\(\[runtime\]\|global_log_path =\)/\1/g' $path_to_your_config_file
```

The path to the global log file can be determined subsequently by running:
To view runtime log output,

```bash
$ cc-runtime cc-env | grep GlobalLogPath
$ sudo journalctl -t cc-runtime
```

Note that it is also possible to enable the global log by setting the
`CC_RUNTIME_GLOBAL_LOG` environment variable to a suitable path. The
environment variable takes priority over the configuration file.

The global logfile path must be specified as an absolute path. If the
directory specified by the logfile path does not exist, the runtime will
attempt to create it.

It is the Administrator's responsibility to ensure there is sufficient
space for the global log.

### Enabling debug for various components

The runtime, the shim (`cc-shim`), and the hypervisor all have separate debug
Expand Down
12 changes: 0 additions & 12 deletions cc-check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,6 @@ func TestCCCheckCLIFunction(t *testing.T) {
}
defer os.RemoveAll(dir)

logfile := filepath.Join(dir, "global.log")

savedSysModuleDir := sysModuleDir
savedProcCPUInfo := procCPUInfo

Expand Down Expand Up @@ -813,15 +811,8 @@ func TestCCCheckCLIFunction(t *testing.T) {
ccLog.Logger.Out = savedLogOutput
}()

assert.False(fileExists(logfile))

err = handleGlobalLog(logfile)
assert.NoError(err)

setupCheckHostIsClearContainersCapable(assert, cpuInfoFile, cpuData, moduleData)

assert.True(fileExists(logfile))

app := cli.NewApp()
ctx := cli.NewContext(app, nil, nil)
app.Name = "foo"
Expand All @@ -831,9 +822,6 @@ func TestCCCheckCLIFunction(t *testing.T) {

err = fn(ctx)
assert.NoError(err)

err = grep(successMessage, logfile)
assert.NoError(err)
}

func TestCCCheckCLIFunctionFail(t *testing.T) {
Expand Down
21 changes: 7 additions & 14 deletions cc-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
//
// XXX: Increment for every change to the output format
// (meaning any change to the EnvInfo type).
const formatVersion = "1.0.5"
const formatVersion = "1.0.6"

// MetaInfo stores information on the format of the output itself
type MetaInfo struct {
Expand All @@ -57,8 +57,7 @@ type CPUInfo struct {

// RuntimeConfigInfo stores runtime config details.
type RuntimeConfigInfo struct {
Path string
GlobalLogPath string
Path string
}

// RuntimeInfo stores runtime details.
Expand Down Expand Up @@ -137,16 +136,15 @@ func getMetaInfo() MetaInfo {
}
}

func getRuntimeInfo(configFile, logFile string, config oci.RuntimeConfig) RuntimeInfo {
func getRuntimeInfo(configFile string, config oci.RuntimeConfig) RuntimeInfo {
runtimeVersion := RuntimeVersionInfo{
Semver: version,
Commit: commit,
OCI: specs.Version,
}

runtimeConfig := RuntimeConfigInfo{
GlobalLogPath: logFile,
Path: configFile,
Path: configFile,
}

return RuntimeInfo{
Expand Down Expand Up @@ -270,10 +268,10 @@ func getHypervisorInfo(config oci.RuntimeConfig) HypervisorInfo {
}
}

func getEnvInfo(configFile, logfilePath string, config oci.RuntimeConfig) (env EnvInfo, err error) {
func getEnvInfo(configFile string, config oci.RuntimeConfig) (env EnvInfo, err error) {
meta := getMetaInfo()

ccRuntime := getRuntimeInfo(configFile, logfilePath, config)
ccRuntime := getRuntimeInfo(configFile, config)

ccHost, err := getHostInfo()
if err != nil {
Expand Down Expand Up @@ -347,12 +345,7 @@ func handleSettings(file *os.File, metadata map[string]interface{}) error {
return errors.New("cannot determine runtime config")
}

logfilePath, ok := metadata["logfilePath"].(string)
if !ok {
return errors.New("cannot determine logfile config")
}

ccEnv, err := getEnvInfo(configFile, logfilePath, runtimeConfig)
ccEnv, err := getEnvInfo(configFile, runtimeConfig)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit f98e619

Please sign in to comment.