<commit_before>package transports

// common.go: Common routines for transports
//
// This file is part of netbackup (http://github.com/marcopaganini/netbackup)
// See instructions in the README.md file that accompanies this program.
// (C) 2015 by <NAME> <paganini AT paganini DOT net>

import (
	"os"
	"path/filepath"
	"time"
)

func createLogFile(logDir string, logFile string, configName string, dirMode os.FileMode, fileMode os.FileMode) (*os.File, string, error) {
	var (
		path string
	)

	// If logfile is set, use it as the name of the log file. If not, generate
	// a standard name under logDir and create any intermediate directories as
	// needed.
	if logFile == "" {
		dir := filepath.Join(logDir, configName)
		if err := os.MkdirAll(dir, dirMode); err != nil {
			return nil, "", err
		}
		ymd := time.Now().Format("2006-01-02")
		path = filepath.Join(dir, configName+"-"+ymd+".log")
	}

	w, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, fileMode)
	if err != nil {
		return nil, path, err
	}
	return w, path, err
}<commit_msg>Bugfix: Trying to log to a specific file caused error.<commit_after>package transports

// common.go: Common routines for transports
//
// This file is part of netbackup (http://github.com/marcopaganini/netbackup)
// See instructions in the README.md file that accompanies this program.
// (C) 2015 by <NAME> <paganini AT paganini DOT net>

import (
	"fmt"
	"os"
	"path/filepath"
	"time"
)

func createLogFile(logDir string, logFile string, configName string, dirMode os.FileMode, fileMode os.FileMode) (*os.File, string, error) {
	// If logfile is set, use it as the name of the log file. If not, generate
	// a standard name under logDir and create any intermediate directories as
	// needed.

	path := logFile
	if path == "" {
		dir := filepath.Join(logDir, configName)
		if err := os.MkdirAll(dir, dirMode); err != nil {
			return nil, "", fmt.Errorf("Error trying to crete dir tree %q: %v", dir, err)
		}
		ymd := time.Now().Format("2006-01-02")
		path = filepath.Join(dir, configName+"-"+ymd+".log")
	}

	w, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, fileMode)
	if err != nil {
		return nil, path, fmt.Errorf("Error opening %q: %v", path, err)
	}
	return w, path, err
}
{'fraction_non_alphanumeric': 0.1368888888888889, 'fraction_numerical': 0.010666666666666666, 'mean_word_length': 3.7489451476793247, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4361825', 'n_tokens_mistral': 829, 'n_tokens_neox': 778, 'n_words': 257}