package cmd import ( "github.com/spf13/cobra" "repair/helpers" "repair/logger" ) func init() { rootCmd.AddCommand(logCmd) } var logCmd = &cobra.Command{ Use: "log", Short: "Check the idea.log file for errors", Long: "Log aspect analyzes idea.log file for exceptions generated by plugins and other exceptions. ", PreRun: func(cmd *cobra.Command, args []string) { logger.InfoLogger.Println("Logs aspect started") }, Run: func(cmd *cobra.Command, args []string) { RunLogAspect(args) }, PostRun: func(cmd *cobra.Command, args []string) { logger.InfoLogger.Println("Logs aspect finished") }, } func RunLogAspect(args []string) { ideaLogPath := helpers.GetIdeaLogPath(helpers.CurrentIde.Binary) if ideaLogPath == "" { logger.InfoLogger.Println("No idea.log file found") return } helpers.CurrentIde.AskUserAndDisablePlugins(helpers.GetPluginsWithExceptionsInIdeaLog(ideaLogPath)) helpers.CurrentIde.AskUserToRunIdeAndCheckTheIssue() exceptions := helpers.GetLogEntriesWithExceptions(ideaLogPath) if len(exceptions) > 0 { logger.ConsoleLogger.Println("There are exceptions unrelated to plugins in idea.log") logExceptions(exceptions) helpers.CurrentIde.AskUserAndClearSystemDirectory() } } func logExceptions(exceptions []helpers.LogEntry) { logger.DebugLogger.Println("The following exceptions occurred:") for _, exception := range exceptions { logger.DebugLogger.Println("\n" + exception.DateAndTime + " " + exception.Severity + " " + exception.Header + "\n" + exception.Body) } }