<commit_before>package cmd

import (
	"fmt"
	"os"
	"os/exec"
	"strings"

	"github.com/open-falcon/falcon-plus/g"
	"github.com/spf13/cobra"
)

var Monitor = &cobra.Command{
	Use:   "tail [Module ...]",
	Short: "Display an Open-Falcon module's log",
	Long: `
Display the log of the specified Open-Falcon module.
A module represents a single node in a cluster.
Modules:
  ` + strings.Join(g.AllModulesInOrder, " "),
	RunE: monitor,
}

func monitor(c *cobra.Command, args []string) error {
	if len(args) != 1 {
		return c.Usage()
	}
	moduleName := args[0]
	err := g.ModuleExists(moduleName)
	if err != nil {
		fmt.Println(err)
		fmt.Println("** start failed **")
		return nil //g.Command_EX_ERR
	}

	logPath := g.LogPath(moduleName)
	cmd := exec.Command("tail", "-f", logPath)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	dir, _ := os.Getwd()
	cmd.Dir = dir
	err = cmd.Run()
	if err != nil {
		fmt.Println("** tail failed **")
		return nil //g.Command_EX_ERR
	}
	return nil //0
}<commit_msg>Redesign of `monitor` command<commit_after>package cmd

import (
	"fmt"
	"os"
	"os/exec"
	"strings"

	"github.com/open-falcon/falcon-plus/g"
	"github.com/spf13/cobra"
)

var Monitor = &cobra.Command{
	Use:   "monitor [Module ...]",
	Short: "Display an Open-Falcon module's log",
	Long: `
Display the log of the specified Open-Falcon module.
A module represents a single node in a cluster.
Modules:
  ` + strings.Join(g.AllModulesInOrder, " "),
	RunE: monitor,
}

func monitor(c *cobra.Command, args []string) error {
	if len(args) != 1 {
		return c.Usage()
	}
	moduleName := args[0]
	if !g.HasModule(moduleName) {
		return fmt.Errorf("%s doesn't exist\n", moduleName)
	}

	logPath := g.LogPath(moduleName)
	cmd := exec.Command("tail", "-f", logPath)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	return cmd.Run()
}
{'fraction_non_alphanumeric': 0.1625207296849088, 'fraction_numerical': 0.004975124378109453, 'mean_word_length': 3.6891191709844557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1300746', 'n_tokens_mistral': 737, 'n_tokens_neox': 715, 'n_words': 174}