Skip to content

Commit bc71831

Browse files
committed
Consistent filename handling in logs
1 parent 7215559 commit bc71831

File tree

6 files changed

+36
-25
lines changed

6 files changed

+36
-25
lines changed

mdimporter/GetMetadataForFile.m

+5-5
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ Boolean GetMetadataForFile(void *thisInterface, CFMutableDictionaryRef attribute
160160
{
161161
if (!logger)
162162
logger = os_log_create("uk.org.marginal.qlvideo", "mdimporter");
163-
os_log_info(logger, "Import with UTI=%{public}@ for %{public}@", contentTypeUTI, pathToFile);
163+
os_log_info(logger, "Import " LOGPRIVATE " with UTI=%{public}@", pathToFile, contentTypeUTI);
164164

165165
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, pathToFile, kCFURLPOSIXPathStyle, false);
166166
Snapshotter *snapshotter = [[Snapshotter alloc] initWithURL:url];
167167
if (!snapshotter) {
168-
os_log_error(logger, "Can't import %@", pathToFile);
168+
os_log_error(logger, "Can't import " LOGPRIVATE, pathToFile);
169169
return false;
170170
}
171171

@@ -242,7 +242,7 @@ Boolean GetMetadataForFile(void *thisInterface, CFMutableDictionaryRef attribute
242242
} else if (!strcasecmp(tag->key, "wm/mediaoriginalbroadcastdatetime")) {
243243
attrs[(__bridge NSString *)kMDItemRecordingDate] = dateString(@(tag->value));
244244
} else {
245-
os_log_info(logger, "Skipping unknown tag %{public}s=%{public}s in %{public}@", tag->key, tag->value, pathToFile);
245+
os_log_info(logger, "Skipping unknown tag %{public}s=%{public}s in " LOGPRIVATE, tag->key, tag->value, pathToFile);
246246
}
247247
}
248248

@@ -326,7 +326,7 @@ Boolean GetMetadataForFile(void *thisInterface, CFMutableDictionaryRef attribute
326326
break;
327327

328328
default:
329-
os_log_info(logger, "Skipping unknown stream #%d:%{public}s in %{public}@", stream_idx, title ? title->value : "", pathToFile);
329+
os_log_info(logger, "Skipping unknown stream #%d:%{public}s in " LOGPRIVATE, stream_idx, title ? title->value : "", pathToFile);
330330
}
331331

332332
// All recognised types
@@ -389,7 +389,7 @@ Boolean GetMetadataForFile(void *thisInterface, CFMutableDictionaryRef attribute
389389
const char *profile = av_get_profile_name(codec, params->profile);
390390
addArrayAttributeNoDupes(attrs, (__bridge NSString *)kMDItemCodecs, profile ? [NSString stringWithFormat:@"%s [%s]", name, profile] : @(name));
391391
} else {
392-
os_log_info(logger, "Unsupported codec with id %d for stream #%d:%{public}s in %{public}@", params->codec_id, stream_idx, title ? title->value : "", pathToFile);
392+
os_log_info(logger, "Unsupported codec with id %d for stream #%d:%{public}s in " LOGPRIVATE, params->codec_id, stream_idx, title ? title->value : "", pathToFile);
393393
}
394394
} // From each stream
395395
}

qlgenerator/GeneratePreviewForURL.m

+9-9
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
8686

8787
@autoreleasepool
8888
{
89-
os_log_info(logger, "Preview with options=%{public}@ UTI=%{public}@ for %{public}@", options, contentTypeUTI, [(__bridge NSURL*)url path]);
89+
os_log_info(logger, "Preview " LOGPRIVATE " with options=%{public}@ UTI=%{public}@", [(__bridge NSURL*)url path], options, contentTypeUTI);
9090
Snapshotter *snapshotter = nil;
9191

9292
// Prefer any cover art (if present) over a playable preview or static snapshot in Finder and Spotlight views
@@ -100,7 +100,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
100100
if (cover)
101101
{
102102
CGSize coversize = CGSizeMake(CGImageGetWidth(cover), CGImageGetHeight(cover));
103-
os_log_info(logger, "Supplying %dx%d cover art for %{public}@", (int) coversize.width, (int) coversize.height, [(__bridge NSURL*)url path]);
103+
os_log_info(logger, "Supplying %dx%d cover art for " LOGPRIVATE, (int) coversize.width, (int) coversize.height, [(__bridge NSURL*)url path]);
104104
CGContextRef context = QLPreviewRequestCreateContext(preview, coversize, true, nil);
105105
CGContextDrawImage(context, CGRectMake(0, 0, coversize.width, coversize.height), cover);
106106
QLPreviewRequestFlushContext(preview, context);
@@ -116,8 +116,8 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
116116
if (QLPreviewRequestIsCancelled(preview)) return kQLReturnNoError;
117117
CFBundleRef myBundle = QLPreviewRequestGetGeneratorBundle(preview);
118118
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:kSettingsSuiteName];
119-
os_log_debug(logger, "QLvideo preview defaults=%@", defaults);
120-
os_log_debug(logger, "QLvideo preview SnapshoCount=%ld", (long)[defaults integerForKey:kSettingsSnapshotCount]);
119+
os_log_debug(logger, "QLvideo preview defaults=%{public}@", defaults);
120+
os_log_debug(logger, "QLvideo preview SnapshotCount=%ld", (long)[defaults integerForKey:kSettingsSnapshotCount]);
121121

122122
if (![defaults boolForKey:kSettingsSnapshotAlways])
123123
@autoreleasepool // Reduce peak footprint
@@ -126,7 +126,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
126126

127127
if (player.playable)
128128
{
129-
os_log_info(logger, "Handing off %{public}@ to AVFoundation", [(__bridge NSURL*)url path]);
129+
os_log_info(logger, "Handing off " LOGPRIVATE " to AVFoundation", [(__bridge NSURL*)url path]);
130130
NSString *title = [player title];
131131
if (!title)
132132
title = [(__bridge NSURL *)url lastPathComponent];
@@ -165,7 +165,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
165165
if (cover)
166166
{
167167
CGSize coversize = CGSizeMake(CGImageGetWidth(cover), CGImageGetHeight(cover));
168-
os_log_info(logger, "Supplying %dx%d cover art for %{public}@", (int) coversize.width, (int) coversize.height, [(__bridge NSURL*)url path]);
168+
os_log_info(logger, "Supplying %dx%d cover art for " LOGPRIVATE, (int) coversize.width, (int) coversize.height, [(__bridge NSURL*)url path]);
169169
NSDictionary *properties = @{(NSString *) kQLPreviewPropertyDisplayNameKey: theTitle};
170170
CGContextRef context = QLPreviewRequestCreateContext(preview, coversize, true, (__bridge CFDictionaryRef) properties);
171171
CGContextDrawImage(context, CGRectMake(0, 0, coversize.width, coversize.height), cover);
@@ -247,7 +247,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
247247
(__bridge NSString *) kQLPreviewPropertyPageElementXPathKey: @"/html/body/div",
248248
(NSString *) kQLPreviewPropertyPDFStyleKey: @(kQLPreviewPDFPagesWithThumbnailsOnLeftStyle),
249249
(NSString *) kQLPreviewPropertyAttachmentsKey: attachments};
250-
os_log_info(logger, "Supplying %lu %dx%d images for %{public}@", [properties[(NSString *) kQLPreviewPropertyAttachmentsKey] count], (int) scaled.width, (int) scaled.height, [(__bridge NSURL*)url path]);
250+
os_log_info(logger, "Supplying %lu %dx%d images for " LOGPRIVATE, [properties[(NSString *) kQLPreviewPropertyAttachmentsKey] count], (int) scaled.width, (int) scaled.height, [(__bridge NSURL*)url path]);
251251
QLPreviewRequestSetDataRepresentation(preview, (__bridge CFDataRef) [html dataUsingEncoding:NSUTF8StringEncoding], kUTTypeHTML,
252252
(__bridge CFDictionaryRef) properties);
253253
return kQLReturnNoError; // early exit
@@ -275,7 +275,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
275275
else
276276
size = CGSizeMake(round(original.width * kMaxHeight / original.height), kMaxHeight);
277277
# endif
278-
os_log_info(logger, "Supplying %dx%d image for %{public}@", (int) size.width, (int) size.height, [(__bridge NSURL*)url path]);
278+
os_log_info(logger, "Supplying %dx%d image for " LOGPRIVATE, (int) size.width, (int) size.height, [(__bridge NSURL*)url path]);
279279
NSDictionary *properties = @{(NSString *) kQLPreviewPropertyDisplayNameKey: theTitle};
280280
CGContextRef context = QLPreviewRequestCreateContext(preview, size, true, (__bridge CFDictionaryRef) properties);
281281
CGContextDrawImage(context, CGRectMake(0, 0, size.width, size.height), thePreview);
@@ -285,7 +285,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
285285
}
286286
else
287287
{
288-
os_log_error(logger, "Can't supply anything for %@", [(__bridge NSURL*)url path]);
288+
os_log_error(logger, "Can't supply anything for " LOGPRIVATE, [(__bridge NSURL*)url path]);
289289
}
290290
}
291291
return kQLReturnNoError;

qlgenerator/GenerateThumbnailForURL.m

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
4242
#ifndef DEBUG // Skip this check to enable debugging with qlmanage -t ...
4343
// On Catalina and later the QLThumbnailGenerator application extension generates thumbnails. On Ventura and later this isn't even called.
4444
if (newQuickLook) {
45-
os_log_info(logger, "Ignoring thumbnail with options=%{public}@ UTI=%{public}@ size=%dx%d for %{public}@", options, contentTypeUTI, (int) maxSize.width, (int) maxSize.height, url);
45+
os_log_info(logger, "Ignoring thumbnail request for " LOGPRIVATE " with options=%{public}@ UTI=%{public}@ size=%dx%d", url, options, contentTypeUTI, (int) maxSize.width, (int) maxSize.height);
4646
return kQLReturnNoError;
4747
}
4848
#endif
@@ -51,14 +51,16 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
5151

5252
@autoreleasepool
5353
{
54-
os_log_info(logger, "Thumbnail with options=%{public}@ UTI=%{public}@ size=%dx%d for %{public}@", options, contentTypeUTI, (int) maxSize.width, (int) maxSize.height, url);
54+
os_log_info(logger, "Thumbnail " LOGPRIVATE " with options=%{public}@ UTI=%{public}@ size=%dx%d", url, options, contentTypeUTI, (int) maxSize.width, (int) maxSize.height);
5555
Snapshotter *snapshotter = [[Snapshotter alloc] initWithURL:url];
5656
if (!snapshotter) return kQLReturnNoError;
5757

5858
// Use cover art if present
5959
snapshot = [snapshotter newCoverArtWithMode:CoverArtThumbnail];
6060
if (snapshot)
6161
{
62+
os_log_info(logger, "Supplying %ldx%ld cover art for " LOGPRIVATE, CGImageGetWidth(snapshot), CGImageGetHeight(snapshot), url);
63+
6264
CFStringRef flavor = newQuickLook ? kQLThumbnailPropertyIconFlavorKey_10_15 : kQLThumbnailPropertyIconFlavorKey;
6365
NSDictionary *properties = @{(__bridge NSString *) flavor: @(kQLThumbnailIconGlossFlavor) }; // suppress letterbox mattes
6466
QLThumbnailRequestSetImage(thumbnail, snapshot, (__bridge CFDictionaryRef) properties);
@@ -95,6 +97,8 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
9597

9698
if (snapshot)
9799
{
100+
os_log_info(logger, "Supplying %ldx%ld snapshot/picture for " LOGPRIVATE, CGImageGetWidth(snapshot), CGImageGetHeight(snapshot), url);
101+
98102
// explicitly request letterbox mattes for UTIs that don't derive from public.media, such as com.microsoft.advanced-systems-format
99103
CFStringRef flavor = newQuickLook ? kQLThumbnailPropertyIconFlavorKey_10_15 : kQLThumbnailPropertyIconFlavorKey;
100104
NSDictionary *properties = @{(__bridge NSString *) flavor: @(kQLThumbnailIconMovieFlavor) };

qlgenerator/Snapshotter.h

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
#include "libavformat/avformat.h"
1414

1515

16+
#ifdef DEBUG
17+
#define LOGPRIVATE "%{public}@"
18+
#else
19+
#define LOGPRIVATE "%{mask.hash}@"
20+
#endif
21+
22+
1623
typedef NS_ENUM(NSInteger, CoverArtMode)
1724
{
1825
CoverArtDefault = 0,

qlgenerator/Snapshotter.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ - (instancetype) initWithURL:(CFURLRef)url
112112
if (!(self = [super init]))
113113
return nil;
114114

115-
116-
if (avformat_open_input(&fmt_ctx, [[(__bridge NSURL*) url path] UTF8String], NULL, NULL))
115+
int ret;
116+
if ((ret = avformat_open_input(&fmt_ctx, [[(__bridge NSURL*) url path] UTF8String], NULL, NULL)))
117117
{
118-
os_log_error(logger, "Can't open %@", [(__bridge NSURL*) url path]);
118+
os_log_error(logger, "Can't open " LOGPRIVATE " - %{public}s", [(__bridge NSURL*) url path], av_err2str(ret));
119119
return nil;
120120
}
121121

thumbnailer/ThumbnailProvider.m

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@ - (void)provideThumbnailForFileRequest:(QLFileThumbnailRequest *)request complet
5959
if (!logger)
6060
logger = os_log_create("uk.org.marginal.qlvideo", "thumbnailer");
6161

62-
os_log_info(logger, "Thumbnailer with attributes=%{public}@ scale=%.2lf minimumSize=%dx%d maximumSize=%dx%d for %{public}@",
62+
os_log_info(logger, "Thumbnailer " LOGPRIVATE " with attributes=%{public}@ scale=%.2lf minimumSize=%dx%d maximumSize=%dx%d",
63+
request.fileURL,
6364
request.attributeKeys, request.scale,
6465
(int) request.minimumSize.width, (int) request.minimumSize.height,
65-
(int) request.maximumSize.width, (int) request.maximumSize.height,
66-
request.fileURL);
66+
(int) request.maximumSize.width, (int) request.maximumSize.height);
6767

6868
// @autoreleasepool
6969
{
7070
Snapshotter *snapshotter = [[Snapshotter alloc] initWithURL:(__bridge CFURLRef) request.fileURL];
7171
if (!snapshotter)
7272
{
73-
os_log_error(logger, "Can't supply anything for %@", request.fileURL);
73+
os_log_error(logger, "Can't supply anything for " LOGPRIVATE, request.fileURL);
7474
return;
7575
}
7676

@@ -122,7 +122,7 @@ - (void)provideThumbnailForFileRequest:(QLFileThumbnailRequest *)request complet
122122
}
123123

124124
if (snapshot) {
125-
os_log_info(logger, "Supplying %dx%d %s for %{public}@", (int) snapshotsize.width, (int) snapshotsize.height,
125+
os_log_info(logger, "Supplying %dx%d %s for " LOGPRIVATE, (int) snapshotsize.width, (int) snapshotsize.height,
126126
isCoverArt ? "cover art" : ([snapshotter pictures] ? "picture" : "snapshot"), request.fileURL);
127127

128128
// explicitly request letterbox mattes for UTIs that don't derive from public.media such as com.microsoft.advanced-systems-format, and explicitly suppress them for cover art
@@ -138,7 +138,7 @@ - (void)provideThumbnailForFileRequest:(QLFileThumbnailRequest *)request complet
138138
return;
139139
}
140140

141-
os_log_error(logger, "Couldn't get thumbnail for %@", request.fileURL);
141+
os_log_error(logger, "Couldn't get thumbnail for " LOGPRIVATE, request.fileURL);
142142
}
143143
}
144144

0 commit comments

Comments
 (0)