+
+#ifdef __ANDROID__
+static void AndroidPrintMsg (void *d, int type, const vlc_log_t *p_item,
+ const char *format, va_list ap)
+{
+ int verbose = (intptr_t)d;
+ int prio;
+
+ if (verbose < 0 || verbose < (type - VLC_MSG_ERR))
+ return;
+
+ int canc = vlc_savecancel ();
+
+ char *format2;
+ if (asprintf (&format2, "[%0*"PRIxPTR"] %s %s: %s",
+ ptr_width, p_item->i_object_id, p_item->psz_module,
+ p_item->psz_object_type, format) < 0)
+ return;
+ switch (type) {
+ case VLC_MSG_INFO:
+ prio = ANDROID_LOG_INFO;
+ break;
+ case VLC_MSG_ERR:
+ prio = ANDROID_LOG_ERROR;
+ break;
+ case VLC_MSG_WARN:
+ prio = ANDROID_LOG_WARN;
+ break;
+ default:
+ case VLC_MSG_DBG:
+ prio = ANDROID_LOG_DEBUG;
+ }
+ __android_log_vprint (prio, "VLC", format2, ap);
+ free (format2);
+ vlc_restorecancel (canc);
+}
+#endif
+
+/**
+ * Sets the message logging callback.
+ * \param cb message callback, or NULL to reset
+ * \param data data pointer for the message callback
+ */
+void vlc_LogSet (libvlc_int_t *vlc, vlc_log_cb cb, void *opaque)
+{
+ libvlc_priv_t *priv = libvlc_priv (vlc);
+
+ if (cb == NULL)
+ {
+#ifdef __ANDROID__
+ cb = AndroidPrintMsg;
+#else
+#if defined (HAVE_ISATTY) && !defined (_WIN32)
+ if (isatty (STDERR_FILENO) && var_InheritBool (vlc, "color"))
+ cb = PrintColorMsg;
+ else
+#endif
+ cb = PrintMsg;
+#endif // __ANDROID__
+ opaque = (void *)(intptr_t)priv->log.verbose;
+ }
+
+ vlc_rwlock_wrlock (&priv->log.lock);
+ priv->log.cb = cb;
+ priv->log.opaque = opaque;
+ vlc_rwlock_unlock (&priv->log.lock);
+
+ /* Announce who we are */
+ msg_Dbg (vlc, "VLC media player - %s", VERSION_MESSAGE);
+ msg_Dbg (vlc, "%s", COPYRIGHT_MESSAGE);
+ msg_Dbg (vlc, "revision %s", psz_vlc_changeset);
+ msg_Dbg (vlc, "configured with %s", CONFIGURE_LINE);
+}
+
+void vlc_LogInit (libvlc_int_t *vlc)
+{
+ libvlc_priv_t *priv = libvlc_priv (vlc);
+ const char *str;
+
+ if (var_InheritBool (vlc, "quiet"))
+ priv->log.verbose = -1;
+ else
+ if ((str = getenv ("VLC_VERBOSE")) != NULL)
+ priv->log.verbose = atoi (str);
+ else
+ priv->log.verbose = var_InheritInteger (vlc, "verbose");
+
+ vlc_rwlock_init (&priv->log.lock);
+ vlc_LogSet (vlc, NULL, NULL);
+}
+
+void vlc_LogDeinit (libvlc_int_t *vlc)
+{
+ libvlc_priv_t *priv = libvlc_priv (vlc);
+
+ vlc_rwlock_destroy (&priv->log.lock);
+}