[lxc-devel] [lxd/master] lxd/container_lxc: improve log for container start

brauner on Github lxc-bot at linuxcontainers.org
Sun Sep 18 00:16:27 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1226 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160918/2d4b9b4d/attachment.bin>
-------------- next part --------------
From a7b2587cd8c205ea8a52c9d04cb0ea7b8d2affce Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Sun, 18 Sep 2016 02:09:12 +0200
Subject: [PATCH] lxd/container_lxc: improve log for container start

Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
 lxd/container_lxc.go | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 99e7d40..4356cd8 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1399,6 +1399,13 @@ func (c *containerLXC) Start(stateful bool) error {
 		}
 	}
 
+	shared.LogInfo("Starting container",
+		log.Ctx{"name": c.name,
+			"action":        op.action,
+			"creation date": c.creationDate,
+			"ephemeral":     c.ephemeral,
+			"last used":     c.lastUsedDate})
+
 	// Start the LXC container
 	out, err := exec.Command(
 		execPath,
@@ -1416,7 +1423,7 @@ func (c *containerLXC) Start(stateful bool) error {
 
 	if err != nil && !c.IsRunning() {
 		// Attempt to extract the LXC errors
-		log := ""
+		lxcLog := ""
 		logPath := filepath.Join(c.LogPath(), "lxc.log")
 		if shared.PathExists(logPath) {
 			logContent, err := ioutil.ReadFile(logPath)
@@ -1433,24 +1440,38 @@ func (c *containerLXC) Start(stateful bool) error {
 					}
 
 					// Prepend the line break
-					if len(log) == 0 {
-						log += "\n"
+					if len(lxcLog) == 0 {
+						lxcLog += "\n"
 					}
 
-					log += fmt.Sprintf("  %s\n", strings.Join(fields[0:], " "))
+					lxcLog += fmt.Sprintf("  %s\n", strings.Join(fields[0:], " "))
 				}
 			}
 		}
 
+		shared.LogError("Failed starting container",
+			log.Ctx{"name": c.name,
+				"action":        op.action,
+				"creation date": c.creationDate,
+				"ephemeral":     c.ephemeral,
+				"last used":     c.lastUsedDate})
+
 		// Return the actual error
 		return fmt.Errorf(
 			"Error calling 'lxd forkstart %s %s %s': err='%v'%s",
 			c.name,
 			c.daemon.lxcpath,
 			filepath.Join(c.LogPath(), "lxc.conf"),
-			err, log)
+			err, lxcLog)
 	}
 
+	shared.LogInfo("Started container",
+		log.Ctx{"name": c.name,
+			"action":        op.action,
+			"creation date": c.creationDate,
+			"ephemeral":     c.ephemeral,
+			"last used":     c.lastUsedDate})
+
 	return nil
 }
 


More information about the lxc-devel mailing list