github.com/Psiphon-Labs/psiphon-tunnel-core@v2.0.28+incompatible/Server/logging/main.go (about) 1 /* 2 * Copyright (c) 2018, Psiphon Inc. 3 * All rights reserved. 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package main 21 22 import ( 23 "flag" 24 "fmt" 25 "os" 26 "strings" 27 28 "github.com/Psiphon-Labs/psiphon-tunnel-core/Server/logging/analysis" 29 ) 30 31 type stringListFlag []string 32 33 func (list *stringListFlag) String() string { 34 return strings.Join(*list, ", ") 35 } 36 37 func (list *stringListFlag) Set(flagValue string) error { 38 *list = append(*list, flagValue) 39 return nil 40 } 41 42 func main() { 43 44 var logFileList stringListFlag 45 var printMessages bool 46 var printMetrics bool 47 var printUnknowns bool 48 var printStructure bool 49 var printExample bool 50 51 flag.Var( 52 &logFileList, 53 "file", 54 "file to analyze; flag may be repeated to analyze multiple files") 55 56 flag.BoolVar( 57 &printMessages, 58 "messages", 59 false, 60 "display message type logs") 61 62 flag.BoolVar( 63 &printMetrics, 64 "metrics", 65 false, 66 "display metric type logs") 67 68 flag.BoolVar( 69 &printUnknowns, 70 "unknown", 71 false, 72 "display logs of an unknown type") 73 74 flag.BoolVar( 75 &printStructure, 76 "structure", 77 false, 78 "print each log model with its key graph structure") 79 80 flag.BoolVar( 81 &printExample, 82 "example", 83 false, 84 "print each log model with an example") 85 86 flag.Usage = func() { 87 fmt.Fprintf(os.Stderr, 88 "Usage:\n\n"+ 89 "%s <flags>\n"+ 90 os.Args[0], os.Args[0]+"\n\n") 91 fmt.Printf("\n") 92 flag.PrintDefaults() 93 } 94 95 flag.Parse() 96 97 if len(logFileList) < 1 { 98 flag.Usage() 99 os.Exit(1) 100 } 101 102 logFileStats, err := analysis.NewLogStatsFromFiles(logFileList) 103 if err != nil { 104 fmt.Printf("Error while parsing log files: %s\n", err) 105 os.Exit(1) 106 } 107 108 logFileStats.Print(printMessages, printMetrics, printUnknowns, printStructure, printExample) 109 110 fmt.Printf("Found %d messages, %d metrics and %d unknown logs with a total of %d distinct types of logs\n", 111 logFileStats.MessageLogModels.Count, 112 logFileStats.MetricsLogModels.Count, 113 logFileStats.UnknownLogModels.Count, 114 logFileStats.NumDistinctLogs()) 115 }