static JSValue js_print_ex(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, u32 ltool, u32 error_type)
{
    int i=0;
    Bool first=GF_TRUE;
    s32 logl = GF_LOG_INFO;
    JSValue v, g;
    const char *c_logname=NULL;
    const char *log_name = "JS";

    if ((argc>1) && JS_IsNumber(argv[0])) {
		JS_ToInt32(ctx, &logl, argv[0]);
		i=1;
	}

	if (error_type)
		logl = GF_LOG_ERROR;
	g = JS_GetGlobalObject(ctx);
	v = JS_GetPropertyStr(ctx, g, "_gpac_log_name");
	if (!JS_IsUndefined(v) && !JS_IsNull(v)) {
		c_logname = JS_ToCString(ctx, v);
		JS_FreeValue(ctx, v);
		if (c_logname) {
			log_name = c_logname;
			if (!strlen(log_name))
				log_name = NULL;
		}
	}
	JS_FreeValue(ctx, g);

	if (log_name) {
#ifndef GPAC_DISABLE_LOG
		GF_LOG(logl, ltool, ("[%s] ", log_name));
#else
		fprintf(stderr, "[%s] ", log_name);
#endif
	}
	if (error_type==2) {
#ifndef GPAC_DISABLE_LOG
		GF_LOG(logl, ltool, ("Throw "));
#else
		fprintf(stderr, "Throw ");
#endif
	}

    for (; i < argc; i++) {
		const char *str = JS_ToCString(ctx, argv[i]);
        if (!str) return GF_JS_EXCEPTION(ctx);

        if (logl==-1) {
			gf_sys_format_help(stderr, GF_PRINTARG_HIGHLIGHT_FIRST, "%s\n", str);
		} else if (logl==-2) {
			gf_sys_format_help(stderr, 0, "%s\n", str);
		} else if (logl<0) {
			fprintf(stderr, "%s%s", (first) ? "" : " ", str);
		} else {
#ifndef GPAC_DISABLE_LOG
			GF_LOG(logl, ltool, ("%s%s", (first) ? "" : " ", str));
#else
			fprintf(stderr, "%s%s", (first) ? "" : " ", str);
#endif
			if (JS_IsException(argv[i])) {
				js_dump_error_exc(ctx, argv[i]);
			}
		}
        JS_FreeCString(ctx, str);
        first=GF_FALSE;
    }
#ifndef GPAC_DISABLE_LOG
 	GF_LOG(logl, ltool, ("\n"));
#else
	fprintf(stderr, "\n");
#endif
	if (c_logname) JS_FreeCString(ctx, c_logname);
	return JS_UNDEFINED;
}
static JSValue js_print_ex(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, u32 ltool, u32 error_type)
{
    int i=0;
    Bool first=GF_TRUE;
    s32 logl = GF_LOG_INFO;
    JSValue v, g;
    const char *c_logname=NULL;
    const char *log_name = "JS";

    if ((argc>1) && JS_IsNumber(argv[0])) {
		JS_ToInt32(ctx, &logl, argv[0]);
		i=1;
	}

	if (error_type)
		logl = GF_LOG_ERROR;
	g = JS_GetGlobalObject(ctx);
	v = JS_GetPropertyStr(ctx, g, "_gpac_log_name");
	if (!JS_IsUndefined(v) && !JS_IsNull(v)) {
		c_logname = JS_ToCString(ctx, v);
		JS_FreeValue(ctx, v);
		if (c_logname) {
			log_name = c_logname;
			if (!strlen(log_name))
				log_name = NULL;
		}
	}
	JS_FreeValue(ctx, g);

	if (log_name) {
#ifndef GPAC_DISABLE_LOG
		GF_LOG(logl, ltool, ("[%s] ", log_name));
#else
		fprintf(stderr, "[%s] ", log_name);
#endif
	}
	if (error_type==2) {
#ifndef GPAC_DISABLE_LOG
		GF_LOG(logl, ltool, ("Throw "));
#else
		fprintf(stderr, "Throw ");
#endif
	}

    for (; i < argc; i++) {
		const char *str = JS_ToCString(ctx, argv[i]);
        if (!str) return GF_JS_EXCEPTION(ctx);

        if (logl==-1) {
			gf_sys_format_help(stderr, GF_PRINTARG_HIGHLIGHT_FIRST, "%s\n", str);
		} else if (logl==-2) {
			gf_sys_format_help(stderr, 0, "%s\n", str);
		} else if (logl<0) {
			fprintf(stderr, "%s%s", (first) ? "" : " ", str);
		} else {
#ifndef GPAC_DISABLE_LOG
			GF_LOG(logl, ltool, ("%s%s", (first) ? "" : " ", str));
#else
			fprintf(stderr, "%s%s", (first) ? "" : " ", str);
#endif
			if (JS_IsException(argv[i])) {
				js_dump_error_exc(ctx, argv[i]);
			}
		}
        JS_FreeCString(ctx, str);
        first=GF_FALSE;
    }
#ifndef GPAC_DISABLE_LOG
 	GF_LOG(logl, ltool, ("\n"));
#else
	fprintf(stderr, "\n");
#endif
	if (c_logname) JS_FreeCString(ctx, c_logname);
	return JS_UNDEFINED;
}