+Boolean
+__SC_log_enabled(int level, os_log_t log, os_log_type_t type)
+{
+ if (os_log_type_enabled(log, type)) {
+ return TRUE;
+ }
+
+ if (_sc_log != kSCLogDestinationDefault) {
+ // if os_log'ing not enabled and the messages is targeted to stdout/stderr
+ if (level < LOG_INFO) {
+ // if not LOG_INFO/LOG_DEBUG message, print
+ return TRUE;
+ } else if ((level == LOG_INFO) && _sc_verbose) {
+ // if LOG_INFO and _sc_verbose, print
+ return TRUE;
+ } else if (_sc_debug) {
+ // if _sc_debug, print
+ return TRUE;
+ }
+ }
+
+ if (_SC_isInstallEnvironment()) {
+ // if OSInstaller environment
+ if (level < LOG_INFO) {
+ // if not LOG_INFO/LOG_DEBUG message, syslog
+ return TRUE;
+ } else if ((level == LOG_INFO) && _SC_isAppleInternal()) {
+ // if LOG_INFO and internal, syslog
+ return TRUE;
+ } else if (_sc_debug) {
+ // if _sc_debug, syslog
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+
+void
+__SC_log_send(int level, os_log_t log, os_log_type_t type, os_log_pack_t pack)
+{
+ Boolean addTime = (_sc_log == kSCLogDestinationBoth);
+ char buffer[256];
+ const char *buffer_ptr = buffer;
+ char *composed = NULL;
+ Boolean do_print = FALSE;
+ Boolean do_syslog = FALSE;
+
+ if (_sc_log > kSCLogDestinationFile) {
+ if (_SC_isInstallEnvironment()) {
+ /*
+ * os_log(3) messages are not persisted in the
+ * install environment. So, we use syslog(3)
+ * instead.
+ */
+ do_syslog = TRUE;
+ }
+
+ if (_sc_log >= kSCLogDestinationBoth) {
+ do_print = TRUE; // log AND print requested
+ }
+ } else {
+ do_print = TRUE; // print requested
+ }
+
+ if (!do_print && !do_syslog) {
+ // if only os_log requested
+ os_log_pack_send(pack, log, type);
+ } else if (do_print && !do_syslog) {
+ // if os_log and print requested
+ composed = os_log_pack_send_and_compose(pack, log, type, buffer, sizeof(buffer));
+ } else {
+ // if print-only and/or syslog requested
+ mach_get_times(NULL, &pack->olp_continuous_time, &pack->olp_wall_time);
+ composed = os_log_pack_compose(pack, log, type, buffer, sizeof(buffer));
+ }
+
+ if (do_print &&
+ (
+ (level < LOG_INFO) || // print most messages
+ ((level == LOG_INFO) && _sc_verbose) || // with _sc_verbose, include LOG_INFO
+ _sc_debug // with _sc_debug, include LOG_DEBUG
+ )
+ ) {
+ // if printing
+ pthread_mutex_lock(&lock);
+ if (addTime) {
+ struct tm tm_now;
+ struct timeval tv_now;
+
+ tv_now.tv_sec = (time_t)&pack->olp_wall_time.tv_sec;
+ tv_now.tv_usec = (suseconds_t)((uint64_t)&pack->olp_wall_time.tv_nsec / NSEC_PER_USEC);
+ (void)localtime_r(&tv_now.tv_sec, &tm_now);
+ (void)fprintf(stdout, "%2d:%02d:%02d.%03d ",
+ tm_now.tm_hour, tm_now.tm_min, tm_now.tm_sec, tv_now.tv_usec / 1000);
+ }
+ (void)fprintf(stdout, "%s\n", composed);
+ fflush (stdout);
+ pthread_mutex_unlock(&lock);
+ }
+
+ if (do_syslog &&
+ (
+ (level < LOG_INFO) ||
+ ((level == LOG_INFO) && _SC_isAppleInternal()) ||
+ _sc_debug
+ )
+ ) {
+ // if [install/upgrade] syslog'ing
+ syslog(level | LOG_INSTALL, "%s", composed);
+ }
+
+ if (composed != buffer_ptr) {
+ free(composed);
+ }
+
+ return;
+}
+
+