Add detailed logging for image conversions on cache miss
Log includes: - file path - input/output format - input/output size in bytes - input/output dimensions - size ratio (percentage) Also adds InputWidth, InputHeight, InputFormat to ProcessResult
This commit is contained in:
@@ -187,6 +187,12 @@ type ProcessResult struct {
|
|||||||
Width int
|
Width int
|
||||||
// Height is the output image height
|
// Height is the output image height
|
||||||
Height int
|
Height int
|
||||||
|
// InputWidth is the original image width before processing
|
||||||
|
InputWidth int
|
||||||
|
// InputHeight is the original image height before processing
|
||||||
|
InputHeight int
|
||||||
|
// InputFormat is the detected input format (e.g., "jpeg", "png")
|
||||||
|
InputFormat string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storage handles persistent storage of cached content
|
// Storage handles persistent storage of cached content
|
||||||
|
|||||||
@@ -93,6 +93,9 @@ func (p *ImageProcessor) Process(
|
|||||||
ContentType: ImageFormatToMIME(outputFormat),
|
ContentType: ImageFormatToMIME(outputFormat),
|
||||||
Width: finalBounds.Dx(),
|
Width: finalBounds.Dx(),
|
||||||
Height: finalBounds.Dy(),
|
Height: finalBounds.Dy(),
|
||||||
|
InputWidth: origWidth,
|
||||||
|
InputHeight: origHeight,
|
||||||
|
InputFormat: format,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -162,6 +162,22 @@ func (s *Service) fetchAndProcess(ctx context.Context, req *ImageRequest) (*Imag
|
|||||||
return nil, fmt.Errorf("image processing failed: %w", err)
|
return nil, fmt.Errorf("image processing failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log conversion details
|
||||||
|
inputSize := int64(len(sourceData))
|
||||||
|
outputSize := processResult.ContentLength
|
||||||
|
sizePercent := float64(outputSize) / float64(inputSize) * 100.0 //nolint:mnd // percentage calculation
|
||||||
|
|
||||||
|
s.log.Info("image converted",
|
||||||
|
"file", req.SourcePath,
|
||||||
|
"input_format", processResult.InputFormat,
|
||||||
|
"output_format", req.Format,
|
||||||
|
"input_bytes", inputSize,
|
||||||
|
"output_bytes", outputSize,
|
||||||
|
"input_dimensions", fmt.Sprintf("%dx%d", processResult.InputWidth, processResult.InputHeight),
|
||||||
|
"output_dimensions", fmt.Sprintf("%dx%d", processResult.Width, processResult.Height),
|
||||||
|
"size_ratio", fmt.Sprintf("%.1f%%", sizePercent),
|
||||||
|
)
|
||||||
|
|
||||||
// Store output content to cache
|
// Store output content to cache
|
||||||
metaID, err := s.cache.GetSourceMetadataID(ctx, req)
|
metaID, err := s.cache.GetSourceMetadataID(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user