INNER CODE UNIT · Go

createLogFile

Ne0nd0g/merlin · pkg/agents/agents.go:74

func createLogFile(id uuid.UUID) (agentLog *os.File, err error) {
	current, err := os.Getwd()
	if err != nil {
		slog.Error(err.Error())
		return nil, fmt.Errorf("there was an error getting the current working directory: %s", err)
	}
	dir := filepath.Join(current, "data", "agents")

	// Create a directory for the new agent's files
	if _, err = os.Stat(filepath.Join(dir, id.String())); os.IsNotExist(err) {
		err = os.MkdirAll(filepath.Join(dir, id.String()), 0750)
		if err != nil {
			return nil, fmt.Errorf("pkg/agents.createLogFile(): there was an error creating a directory for agent %s: %s", id, err)
		}
		// Create the agent's log file
		agentLog, err = os.Create(filepath.Join(dir, id.String(), "log.txt")) // #nosec G304 Users can include any file they want
		if err != nil {
			return nil, fmt.Errorf("pkg/agents.createLogFile(): there was an error creating the log.txt file for agent %s: %s", id, err)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…