44
44
45
45
#if defined(__APPLE__ )
46
46
# include <AvailabilityMacros.h>
47
+ # include <TargetConditionals.h>
47
48
# include <mach-o/loader.h>
48
- # include <os/log.h>
49
+ // The os_log unified logging APIs were introduced in macOS 10.12, iOS 10.0,
50
+ // tvOS 10.0, and watchOS 3.0;
51
+ # if defined(TARGET_OS_IPHONE ) && TARGET_OS_IPHONE
52
+ # define HAS_APPLE_SYSTEM_LOG 1
53
+ # elif defined(TARGET_OS_OSX ) && TARGET_OS_OSX
54
+ # if defined(MAC_OS_X_VERSION_10_12 ) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
55
+ # define HAS_APPLE_SYSTEM_LOG 1
56
+ # else
57
+ # define HAS_APPLE_SYSTEM_LOG 0
58
+ # endif
59
+ # else
60
+ # define HAS_APPLE_SYSTEM_LOG 0
61
+ # endif
62
+
63
+ # if HAS_APPLE_SYSTEM_LOG
64
+ # include <os/log.h>
65
+ # endif
49
66
#endif
50
67
51
68
#ifdef HAVE_SIGNAL_H
@@ -75,7 +92,7 @@ static PyStatus init_sys_streams(PyThreadState *tstate);
75
92
#ifdef __ANDROID__
76
93
static PyStatus init_android_streams (PyThreadState * tstate );
77
94
#endif
78
- #if defined(__APPLE__ )
95
+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
79
96
static PyStatus init_apple_streams (PyThreadState * tstate );
80
97
#endif
81
98
static void wait_for_thread_shutdown (PyThreadState * tstate );
@@ -1258,7 +1275,7 @@ init_interp_main(PyThreadState *tstate)
1258
1275
return status ;
1259
1276
}
1260
1277
#endif
1261
- #if defined(__APPLE__ )
1278
+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
1262
1279
if (config -> use_system_logger ) {
1263
1280
status = init_apple_streams (tstate );
1264
1281
if (_PyStatus_EXCEPTION (status )) {
@@ -2933,7 +2950,7 @@ init_android_streams(PyThreadState *tstate)
2933
2950
2934
2951
#endif // __ANDROID__
2935
2952
2936
- #if defined(__APPLE__ )
2953
+ #if defined(__APPLE__ ) && HAS_APPLE_SYSTEM_LOG
2937
2954
2938
2955
static PyObject *
2939
2956
apple_log_write_impl (PyObject * self , PyObject * args )
@@ -2944,14 +2961,9 @@ apple_log_write_impl(PyObject *self, PyObject *args)
2944
2961
return NULL ;
2945
2962
}
2946
2963
2947
- // Call the underlying Apple logging API. The os_log unified logging APIs
2948
- // were introduced in macOS 10.12, iOS 10.0, tvOS 10.0, and watchOS 3.0;
2949
- // this call is a no-op on older versions.
2950
- #if TARGET_OS_IPHONE || (TARGET_OS_OSX && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 )
2951
2964
// Pass the user-provided text through explicit %s formatting
2952
2965
// to avoid % literals being interpreted as a formatting directive.
2953
2966
os_log_with_type (OS_LOG_DEFAULT , logtype , "%s" , text );
2954
- #endif
2955
2967
Py_RETURN_NONE ;
2956
2968
}
2957
2969
@@ -2986,7 +2998,6 @@ init_apple_streams(PyThreadState *tstate)
2986
2998
if (result == NULL ) {
2987
2999
goto error ;
2988
3000
}
2989
-
2990
3001
goto done ;
2991
3002
2992
3003
error :
@@ -3000,7 +3011,7 @@ init_apple_streams(PyThreadState *tstate)
3000
3011
return status ;
3001
3012
}
3002
3013
3003
- #endif // __APPLE__
3014
+ #endif // __APPLE__ && HAS_APPLE_SYSTEM_LOG
3004
3015
3005
3016
3006
3017
static void
0 commit comments