Files
openide/native/repair-utility/cmd/log.go
konstantin.annikov 01f61d2d78 [Repair Utility] move to community
GitOrigin-RevId: af0c92f448088c53578857b0e1b84b95c2664a4e
2022-11-09 16:13:29 +00:00

50 lines
1.5 KiB
Go

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)
}
}