// ProcessEvent generates a configuration log event for the given Task
// reporting identifiers for the currently executing process.
func LogProcess(main *logberry.Task) error {

	hostname, err := os.Hostname()
	if err != nil {
		return logberry.WrapError("Could not retrieve hostname", err)
	}

	wd, err := os.Getwd()
	if err != nil {
		return logberry.WrapError("Could not retrieve working dir", err)
	}

	u, err := user.Current()
	if err != nil {
		return logberry.WrapError("Could not retrieve user info", err)
	}

	d := logberry.D{
		"Host": hostname,
		"WD":   wd,
		"UID":  u.Uid,
		"User": u.Username,
		"PID":  os.Getpid(),
	}

	main.Event(logberry.CONFIGURATION, "Process", d)

	return nil

}
// CommandLineEvent generates a configuration log event for the given
// Task reporting the command line used to execute the currently
// executing process.
func LogCommandLine(main *logberry.Task) error {

	hostname, err := os.Hostname()
	if err != nil {
		return logberry.WrapError("Could not retrieve hostname", err)
	}

	u, err := user.Current()
	if err != nil {
		return logberry.WrapError("Could not retrieve user info", err)
	}

	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		return logberry.WrapError("Could not retrieve program path", err)
	}

	prog := path.Base(os.Args[0])

	d := logberry.D{
		"Host":    hostname,
		"User":    u.Username,
		"Path":    dir,
		"Program": prog,
		"Args":    os.Args[1:],
	}

	main.Event(logberry.CONFIGURATION, "Command line", d)

	return nil

}