1 Star 0 Fork 0

zhuchance/kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
logs.go 2.57 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package services
import (
"encoding/json"
"flag"
"fmt"
)
// LogFileData holds data about logfiles to fetch with a journalctl command or
// file from a node's file system.
type LogFileData struct {
// Name of the log file.
Name string `json:"name"`
// Files are possible absolute paths of the log file.
Files []string `json:"files"`
// JournalctlCommand is the journalctl command to get log.
JournalctlCommand []string `json:"journalctl"`
}
// logFiles are the type used to collect all log files. The key is the expected
// name of the log file after collected.
type logFiles map[string]LogFileData
// String function of flag.Value
func (l *logFiles) String() string {
return fmt.Sprint(*l)
}
// Set function of flag.Value
func (l *logFiles) Set(value string) error {
var log LogFileData
if err := json.Unmarshal([]byte(value), &log); err != nil {
return err
}
// Note that we assume all white space in flag string is separating fields
logs := *l
logs[log.Name] = log
return nil
}
// extraLogs is the extra logs specified by the test runner.
var extraLogs = make(logFiles)
func init() {
flag.Var(&extraLogs, "extra-log", "Extra log to collect after test in the json format of LogFile.")
}
// requiredLogs is the required logs to collect after the test.
var requiredLogs = []LogFileData{
{
Name: "kern.log",
Files: []string{"/var/log/kern.log"},
JournalctlCommand: []string{"-k"},
},
{
Name: "cloud-init.log",
Files: []string{"/var/log/cloud-init.log"},
JournalctlCommand: []string{"-u", "cloud*"},
},
// TODO(random-liu): Make docker.log non-required.
{
Name: "docker.log",
Files: []string{"/var/log/docker.log", "/var/log/upstart/docker.log"},
JournalctlCommand: []string{"-u", "docker"},
},
}
// getLogFiles get all logs to collect after the test.
func getLogFiles() logFiles {
logs := make(logFiles)
for _, l := range requiredLogs {
logs[l.Name] = l
}
for _, l := range extraLogs {
logs[l.Name] = l
}
return logs
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v1.13.2

搜索帮助