Exemple #1
0
func main() {
	app := cli.NewApp()
	app.Name = "gologme"
	app.Usage = "local logging server"
	user, err := user.Current()
	var dbUrl string
	if err != nil {
		dbUrl = "gologme.db"
	} else {
		dbUrl = path.Join(user.HomeDir, ".gologme.db")
	}

	app.Flags = []cli.Flag{
		cli.IntFlag{
			Name:   "port",
			Value:  8080,
			Usage:  "port to listen on",
			EnvVar: "DB_PORT",
		},

		cli.StringFlag{
			Name:   "dbType",
			Usage:  "Database Type (sqlite3, postgres)",
			Value:  "sqlite3",
			EnvVar: "DB_TYPE",
		},
		cli.StringFlag{
			Name:   "dbUrl",
			Usage:  "Database URL",
			Value:  dbUrl,
			EnvVar: "DB_URL",
		},
	}

	app.Action = func(c *cli.Context) {
		server.ServeFromPath(
			c.String("dbType"),
			c.String("dbUrl"),
			fmt.Sprintf(":%d", c.Int("port")),
		)
	}
	app.Run(os.Args)
}
Exemple #2
0
func main() {
	app := cli.NewApp()
	app.Name = "gologme"
	app.Usage = "local logging client"
	user, err := user.Current()
	var defaultDbPath string
	if err != nil {
		defaultDbPath = "gologme.db"
	} else {
		defaultDbPath = path.Join(user.HomeDir, ".gologme.db")
	}

	app.Flags = []cli.Flag{
		cli.IntFlag{
			Name:  "windowLogGranularity",
			Value: 500,
			Usage: "How often to poll window title in ms",
		},
		cli.IntFlag{
			Name:  "keyLogGranularity",
			Value: 1000,
			Usage: "How often to aggregate caught keypresses in ms",
		},
		cli.BoolFlag{
			Name:  "standalone",
			Usage: "Run in non-networked, standalone mode",
		},
		cli.StringFlag{
			Name:  "dbPath",
			Usage: "Path to the database",
			Value: defaultDbPath,
		},
		cli.StringFlag{
			Name:  "serverAddr",
			Usage: "Address to send logs to, defaults to localhost for --standalone mode.",
			Value: "http://127.0.0.1:10000",
		},
	}

	app.Action = func(c *cli.Context) {
		if c.Bool("standalone") {
			serverAddr := c.String("serverAddr")
			if strings.Count(serverAddr, ":") > 1 {
				serverAddr = serverAddr[strings.LastIndex(serverAddr, "/")+1:]
			}

			go server.ServeFromPath(
				"sqlite3",
				c.String("dbPath"),
				serverAddr,
			)
		}

		serverPath := c.String("serverAddr")

		client.Golog(
			c.Int("windowLogGranularity"),
			c.Int("keyLogGranularity"),
			c.Bool("standalone"),
			serverPath,
		)

	}
	app.Run(os.Args)
}