Skip to content

Commit

Permalink
improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Mar 20, 2022
1 parent ce7e7cd commit 5f0ab90
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ func main() {
opt.kubeconfig = os.Getenv("KUBECONFIG")
}

if opt.directory == "" {
opt.directory = fmt.Sprintf("loks-%s", time.Now().Format("2006.01.02T15.04.05"))
}

log.WithField("directory", opt.directory).Info("Storing logs on disk")

if opt.labels != "" {
if _, err := labels.Parse(opt.labels); err != nil {
log.Fatalf("Invalid label selector: %v", err)
Expand All @@ -85,6 +79,12 @@ func main() {
log.Fatal("At least a namespace or a resource name pattern must be given.")
}

if opt.directory == "" {
opt.directory = fmt.Sprintf("loks-%s", time.Now().Format("2006.01.02T15.04.05"))
}

log.WithField("directory", opt.directory).Info("Storing logs on disk.")

c, err := collector.NewDiskCollector(opt.directory, opt.flatFiles)
if err != nil {
log.Fatalf("Failed to create log collector: %v", err)
Expand All @@ -93,7 +93,7 @@ func main() {
// //////////////////////////////////////
// setup kubernetes client

log.Debug("Creating Kubernetes clientset...")
log.Debug("Creating Kubernetes clientset")

config, err := clientcmd.BuildConfigFromFlags("", opt.kubeconfig)
if err != nil {
Expand All @@ -118,7 +118,7 @@ func main() {
Resource: "pods",
})

log.Debug("Starting to watch pods...")
log.Debug("Starting to watch pods")

wi, err := resourceInterface.Watch(rootCtx, metav1.ListOptions{
LabelSelector: opt.labels,
Expand Down
2 changes: 1 addition & 1 deletion pkg/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (w *Watcher) startLogCollectors(ctx context.Context, pod *corev1.Pod) {
}

func (w *Watcher) collectLogs(ctx context.Context, log logrus.FieldLogger, pod *corev1.Pod, containerName string, restartCount int) {
log.Info("Starting to collect logs.")
log.Info("Starting to collect logs")

request := w.clientset.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &corev1.PodLogOptions{
Container: containerName,
Expand Down

0 comments on commit 5f0ab90

Please sign in to comment.