logs

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

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.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

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.

Index

Constants

View Source
const (
	// RFC3339NanoFixed is the fixed width version of time.RFC3339Nano.
	RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
	// RFC3339NanoLenient is the variable width RFC3339 time format for lenient parsing of strings into timestamps.
	RFC3339NanoLenient = "2006-01-02T15:04:05.999999999Z07:00"
)

Variables

View Source
var LogLevel string
View Source
var Logs = &cobra.Command{
	Use:   "logs",
	Short: "Print the logs for a container in a pod",
	Run: func(cmd *cobra.Command, args []string) {
		if vars.MustGatherRootPath == "" {
			fmt.Println("There are no must-gather resources defined.")
			os.Exit(1)
		}
		exist, _ := helpers.Exists(vars.MustGatherRootPath + "/namespaces")
		if !exist {
			files, err := ioutil.ReadDir(vars.MustGatherRootPath)
			if err != nil {
				log.Fatal(err)
			}
			var QuayString string
			for _, f := range files {
				if strings.HasPrefix(f.Name(), "quay") {
					QuayString = f.Name()
					vars.MustGatherRootPath = vars.MustGatherRootPath + "/" + QuayString
					break
				}
			}
			if QuayString == "" {
				fmt.Println("Some error occurred, wrong must-gather file composition")
				os.Exit(1)
			}
		}
		namespaceFlag, _ := cmd.Flags().GetString("namespace")
		if namespaceFlag != "" {
			vars.Namespace = namespaceFlag
		}
		podName := ""
		containerName, _ := cmd.Flags().GetString("container")
		previousFlag, _ := cmd.Flags().GetBool("previous")
		allContainersFlag, _ := cmd.Flags().GetBool("all-containers")
		logLevels := []string{}
		if LogLevel != "" {
			logLevels = strings.Split(LogLevel, ",")
		}

		if len(args) == 0 || len(args) > 2 {
			fmt.Println("error: expected 'logs [-p] (POD | TYPE/NAME) [-c CONTAINER]'.")
			fmt.Println("POD or TYPE/NAME is a required argument for the logs command")
			fmt.Println("See 'omc logs -h' for help and examples")
			os.Exit(1)
		}
		if len(args) == 1 {
			if s := strings.Split(args[0], "/"); len(s) == 2 && (s[0] == "po" || s[0] == "pod" || s[0] == "pods") {
				podName = s[1]
				if podName == "" {
					fmt.Println("error: arguments in resource/name form must have a single resource and name")
					os.Exit(1)
				}
				logsPods(vars.MustGatherRootPath, vars.Namespace, podName, containerName, previousFlag, allContainersFlag, logLevels)
			} else {
				podName = s[0]
				logsPods(vars.MustGatherRootPath, vars.Namespace, podName, containerName, previousFlag, allContainersFlag, logLevels)
			}
		}
		if len(args) == 2 {
			if s := strings.Split(args[0], "/"); len(s) == 2 && (s[0] == "po" || s[0] == "pod" || s[0] == "pods") {
				if containerName != "" {
					fmt.Println("error: only one of -c or an inline [CONTAINER] arg is allowed")
					os.Exit(1)
				} else {
					podName = s[1]
					if podName == "" {
						fmt.Println("error: arguments in resource/name form must have a single resource and name")
						os.Exit(1)
					}
					containerName = args[1]
					logsPods(vars.MustGatherRootPath, vars.Namespace, podName, containerName, previousFlag, allContainersFlag, logLevels)
				}
			} else {
				if containerName != "" {
					fmt.Println("error: only one of -c or an inline [CONTAINER] arg is allowed")
					os.Exit(1)
				} else {
					podName = args[0]
					containerName = args[1]
					logsPods(vars.MustGatherRootPath, vars.Namespace, podName, containerName, previousFlag, allContainersFlag, logLevels)
				}
			}
		}
	},
}

logsCmd represents the logs command

Functions

func FilterCatLogs added in v1.4.0

func FilterCatLogs(filePath string, logLevels []string)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL