Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved some logging messages and --log-level NONE behavior #2845

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
21 changes: 14 additions & 7 deletions cmd/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ func (raw rawCopyCmdArgs) cook() (CookedCopyCmdArgs, error) {
azcopyScanningLogger.CloseLog()
})

// if no logging, set this empty so that we don't display the log location
if azcopyLogVerbosity == common.LogNone {
gapra-msft marked this conversation as resolved.
Show resolved Hide resolved
azcopyLogPathFolder = ""
}

fromTo, err := ValidateFromTo(raw.src, raw.dst, raw.fromTo) // TODO: src/dst
if err != nil {
return cooked, err
Expand Down Expand Up @@ -549,7 +554,7 @@ func (raw rawCopyCmdArgs) cook() (CookedCopyCmdArgs, error) {
}

if cooked.FromTo.To() == common.ELocation.None() && strings.EqualFold(raw.metadata, common.MetadataAndBlobTagsClearFlag) { // in case of Blob, BlobFS and Files
glcm.Info("*** WARNING *** Metadata will be cleared because of input --metadata=clear ")
glcm.Warn("*** WARNING *** Metadata will be cleared because of input --metadata=clear ")
}
cooked.metadata = raw.metadata
if err = validateMetadataString(cooked.metadata); err != nil {
Expand All @@ -573,7 +578,7 @@ func (raw rawCopyCmdArgs) cook() (CookedCopyCmdArgs, error) {
return cooked, errors.New("blob tags can only be set when transferring to blob storage")
}
if cooked.FromTo.To() == common.ELocation.None() && strings.EqualFold(raw.blobTags, common.MetadataAndBlobTagsClearFlag) { // in case of Blob and BlobFS
glcm.Info("*** WARNING *** BlobTags will be cleared because of input --blob-tags=clear ")
glcm.Warn("*** WARNING *** BlobTags will be cleared because of input --blob-tags=clear ")
dphulkar-msft marked this conversation as resolved.
Show resolved Hide resolved
}
blobTags := common.ToCommonBlobTagsMap(raw.blobTags)
err = validateBlobTagsKeyValue(blobTags)
Expand Down Expand Up @@ -901,7 +906,7 @@ var includeWarningOncer = &sync.Once{}
func (raw *rawCopyCmdArgs) warnIfHasWildcard(oncer *sync.Once, paramName string, value string) {
if strings.Contains(value, "*") || strings.Contains(value, "?") {
oncer.Do(func() {
glcm.Info(fmt.Sprintf("*** Warning *** The %s parameter does not support wildcards. The wildcard "+
glcm.Warn(fmt.Sprintf("*** Warning *** The %s parameter does not support wildcards. The wildcard "+
"character provided will be interpreted literally and will not have any wildcard effect. To use wildcards "+
"(in filenames only, not paths) use include-pattern or exclude-pattern", paramName))
})
Expand Down Expand Up @@ -1689,11 +1694,13 @@ func (cca *CookedCopyCmdArgs) waitUntilJobCompletion(blocking bool) {
// print initial message to indicate that the job is starting
// if on dry run mode do not want to print message since no job is being done
if !cca.dryrunMode {
// Output the log location if log-level is set to other then NONE
var logPathFolder string
if azcopyLogPathFolder != "" {
logPathFolder = fmt.Sprintf("%s%s%s.log", azcopyLogPathFolder, common.OS_PATH_SEPARATOR, cca.jobID)
}
glcm.Init(common.GetStandardInitOutputBuilder(cca.jobID.String(),
fmt.Sprintf("%s%s%s.log",
azcopyLogPathFolder,
common.OS_PATH_SEPARATOR,
cca.jobID),
logPathFolder,
cca.isCleanupJob,
cca.cleanupJobMessage))
}
Expand Down
13 changes: 9 additions & 4 deletions cmd/copyEnumeratorHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package cmd

import (
"fmt"
"math/rand"

"github.com/Azure/azure-storage-azcopy/v10/common"
"github.com/Azure/azure-storage-azcopy/v10/jobsAdmin"
"math/rand"
)

var EnumerationParallelism = 1
var EnumerationParallelStatFiles = false

// addTransfer accepts a new transfer, if the threshold is reached, dispatch a job part order.
func addTransfer(e *common.CopyJobPartOrderRequest, transfer common.CopyTransfer, cca *CookedCopyCmdArgs) error {
// Source and destination paths are and should be relative paths.
// Source and destination paths are and should be relative paths.

// dispatch the transfers once the number reaches NumOfFilesPerDispatchJobPart
// we do this so that in the case of large transfer, the transfer engine can get started
Expand Down Expand Up @@ -69,8 +70,12 @@ func dispatchFinalPart(e *common.CopyJobPartOrderRequest, cca *CookedCopyCmdArgs
Rpc(common.ERpcCmd.CopyJobPartOrder(), (*common.CopyJobPartOrderRequest)(e), &resp)

if !resp.JobStarted {
// Output the log location and such
glcm.Init(common.GetStandardInitOutputBuilder(cca.jobID.String(), fmt.Sprintf("%s%s%s.log", azcopyLogPathFolder, common.OS_PATH_SEPARATOR, cca.jobID), cca.isCleanupJob, cca.cleanupJobMessage))
// Output the log location if log-level is set to other then NONE
var logPathFolder string
if azcopyLogPathFolder != "" {
logPathFolder = fmt.Sprintf("%s%s%s.log", azcopyLogPathFolder, common.OS_PATH_SEPARATOR, cca.jobID)
}
glcm.Init(common.GetStandardInitOutputBuilder(cca.jobID.String(), logPathFolder, cca.isCleanupJob, cca.cleanupJobMessage))

if cca.dryrunMode {
return nil
Expand Down
6 changes: 3 additions & 3 deletions cmd/copyEnumeratorInit.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (cca *CookedCopyCmdArgs) initEnumerator(jobPartOrder common.CopyJobPartOrde
// check against seenFailedContainers so we don't spam the job log with initialization failed errors
if _, ok := seenFailedContainers[dstContainerName]; err != nil && jobsAdmin.JobsAdmin != nil && !ok {
logDstContainerCreateFailureOnce.Do(func() {
glcm.Info("Failed to create one or more destination container(s). Your transfers may still succeed if the container already exists.")
glcm.Warn("Failed to create one or more destination container(s). Your transfers may still succeed if the container already exists.")
})
jobsAdmin.JobsAdmin.LogToJobLog(fmt.Sprintf("Failed to create destination container %s. The transfer will continue if the container exists", dstContainerName), common.LogWarning)
jobsAdmin.JobsAdmin.LogToJobLog(fmt.Sprintf("Error %s", err), common.LogDebug)
Expand Down Expand Up @@ -194,7 +194,7 @@ func (cca *CookedCopyCmdArgs) initEnumerator(jobPartOrder common.CopyJobPartOrde
// check against seenFailedContainers so we don't spam the job log with initialization failed errors
if _, ok := seenFailedContainers[bucketName]; err != nil && jobsAdmin.JobsAdmin != nil && !ok {
logDstContainerCreateFailureOnce.Do(func() {
glcm.Info("Failed to create one or more destination container(s). Your transfers may still succeed if the container already exists.")
glcm.Warn("Failed to create one or more destination container(s). Your transfers may still succeed if the container already exists.")
})
jobsAdmin.JobsAdmin.LogToJobLog(fmt.Sprintf("failed to initialize destination container %s; the transfer will continue (but be wary it may fail).", bucketName), common.LogWarning)
jobsAdmin.JobsAdmin.LogToJobLog(fmt.Sprintf("Error %s", err), common.LogDebug)
Expand All @@ -215,7 +215,7 @@ func (cca *CookedCopyCmdArgs) initEnumerator(jobPartOrder common.CopyJobPartOrde

if _, ok := seenFailedContainers[dstContainerName]; err != nil && jobsAdmin.JobsAdmin != nil && !ok {
logDstContainerCreateFailureOnce.Do(func() {
glcm.Info("Failed to create one or more destination container(s). Your transfers may still succeed if the container already exists.")
glcm.Warn("Failed to create one or more destination container(s). Your transfers may still succeed if the container already exists.")
})
jobsAdmin.JobsAdmin.LogToJobLog(fmt.Sprintf("failed to initialize destination container %s; the transfer will continue (but be wary it may fail).", resName), common.LogWarning)
jobsAdmin.JobsAdmin.LogToJobLog(fmt.Sprintf("Error %s", err), common.LogDebug)
Expand Down
12 changes: 11 additions & 1 deletion cmd/jobsResume.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ type resumeJobController struct {
// if blocking is specified to false, then another goroutine spawns and wait out the job
func (cca *resumeJobController) waitUntilJobCompletion(blocking bool) {
// print initial message to indicate that the job is starting
glcm.Init(common.GetStandardInitOutputBuilder(cca.jobID.String(), fmt.Sprintf("%s%s%s.log", azcopyLogPathFolder, common.OS_PATH_SEPARATOR, cca.jobID), false, ""))
// Output the log location if log-level is set to other then NONE
var logPathFolder string
if azcopyLogPathFolder != "" {
logPathFolder = fmt.Sprintf("%s%s%s.log", azcopyLogPathFolder, common.OS_PATH_SEPARATOR, cca.jobID)
}
glcm.Init(common.GetStandardInitOutputBuilder(cca.jobID.String(), logPathFolder, false, ""))

// initialize the times necessary to track progress
cca.jobStartTime = time.Now()
Expand Down Expand Up @@ -324,6 +329,11 @@ func (rca resumeCmdArgs) process() error {
return fmt.Errorf("error parsing the jobId %s. Failed with error %s", rca.jobID, err.Error())
}

// if no logging, set this empty so that we don't display the log location
if azcopyLogVerbosity == common.LogNone {
azcopyLogPathFolder = ""
}

includeTransfer := make(map[string]int)
excludeTransfer := make(map[string]int)

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func init() {
rootCmd.PersistentFlags().Float64Var(&cmdLineCapMegaBitsPerSecond, "cap-mbps", 0, "Caps the transfer rate, in megabits per second. Moment-by-moment throughput might vary slightly from the cap. If this option is set to zero, or it is omitted, the throughput isn't capped.")
rootCmd.PersistentFlags().StringVar(&outputFormatRaw, "output-type", "text", "Format of the command's output. The choices include: text, json. The default value is 'text'.")
rootCmd.PersistentFlags().StringVar(&outputVerbosityRaw, "output-level", "default", "Define the output verbosity. Available levels: essential, quiet.")
rootCmd.PersistentFlags().StringVar(&logVerbosityRaw, "log-level", "INFO", "Define the log verbosity for the log file, available levels: INFO(all requests/responses), WARNING(slow responses), ERROR(only failed requests), and NONE(no output logs). (default 'INFO').")
rootCmd.PersistentFlags().StringVar(&logVerbosityRaw, "log-level", "INFO", "Define the log verbosity for the log file, available levels: DEBUG(detailed trace), INFO(all requests/responses), WARNING(slow responses), ERROR(only failed requests), and NONE(no output logs). (default 'INFO').")

rootCmd.PersistentFlags().StringVar(&cmdLineExtraSuffixesAAD, trustedSuffixesNameAAD, "", "Specifies additional domain suffixes where Azure Active Directory login tokens may be sent. The default is '"+
trustedSuffixesAAD+"'. Any listed here are added to the default. For security, you should only put Microsoft Azure domains here. Separate multiple entries with semi-colons.")
Expand Down
12 changes: 11 additions & 1 deletion cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ func (raw *rawSyncCmdArgs) cook() (cookedSyncCmdArgs, error) {
azcopyScanningLogger.CloseLog()
})

// if no logging, set this empty so that we don't display the log location
if azcopyLogVerbosity == common.LogNone {
gapra-msft marked this conversation as resolved.
Show resolved Hide resolved
azcopyLogPathFolder = ""
}

// this if statement ladder remains instead of being separated to help determine valid combinations for sync
// consider making a map of valid source/dest combos and consolidating this to generic source/dest setups, akin to the lower if statement
// TODO: if expand the set of source/dest combos supported by sync, update this method the declarative test framework:
Expand Down Expand Up @@ -505,7 +510,12 @@ func (cca *cookedSyncCmdArgs) scanningComplete() bool {
// if blocking is specified to false, then another goroutine spawns and wait out the job
func (cca *cookedSyncCmdArgs) waitUntilJobCompletion(blocking bool) {
// print initial message to indicate that the job is starting
glcm.Init(common.GetStandardInitOutputBuilder(cca.jobID.String(), fmt.Sprintf("%s%s%s.log", azcopyLogPathFolder, common.OS_PATH_SEPARATOR, cca.jobID), false, ""))
// Output the log location if log-level is set to other then NONE
var logPathFolder string
if azcopyLogPathFolder != "" {
logPathFolder = fmt.Sprintf("%s%s%s.log", azcopyLogPathFolder, common.OS_PATH_SEPARATOR, cca.jobID)
}
glcm.Init(common.GetStandardInitOutputBuilder(cca.jobID.String(), logPathFolder, false, ""))

// initialize the times necessary to track progress
cca.jobStartTime = time.Now()
Expand Down
4 changes: 3 additions & 1 deletion common/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ func GetStandardInitOutputBuilder(jobID string, logFileLocation string, isCleanu
sb.WriteString(cleanupHeader)
} else {
sb.WriteString("\nJob " + jobID + " has started\n")
sb.WriteString("Log file is located at: " + logFileLocation)
if logFileLocation != "" {
sb.WriteString("Log file is located at: " + logFileLocation)
}
sb.WriteString("\n")
}
return sb.String()
Expand Down
Loading