jaroslav@1230: /** jaroslav@1230: * Back 2 Browser Bytecode Translator jaroslav@1230: * Copyright (C) 2012 Jaroslav Tulach jaroslav@1230: * jaroslav@1230: * This program is free software: you can redistribute it and/or modify jaroslav@1230: * it under the terms of the GNU General Public License as published by jaroslav@1230: * the Free Software Foundation, version 2 of the License. jaroslav@1230: * jaroslav@1230: * This program is distributed in the hope that it will be useful, jaroslav@1230: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@1230: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@1230: * GNU General Public License for more details. jaroslav@1230: * jaroslav@1230: * You should have received a copy of the GNU General Public License jaroslav@1230: * along with this program. Look for COPYING file in the top folder. jaroslav@1230: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@1230: */ jaroslav@1230: package org.apidesign.bck2brwsr.kofx; jaroslav@1230: jaroslav@1230: import java.util.logging.Logger; jaroslav@1230: import net.java.html.js.JavaScriptBody; jaroslav@1230: jaroslav@1230: /** This is an implementation package - just jaroslav@1230: * include its JAR on classpath and use official {@link Context} API jaroslav@1230: * to access the functionality. jaroslav@1230: *

jaroslav@1230: * Redirects JavaScript's messages to Java's {@link Logger}. jaroslav@1230: * jaroslav@1230: * @author Jaroslav Tulach jaroslav@1230: */ jaroslav@1230: public final class Console { jaroslav@1230: private static final Logger LOG = Logger.getLogger(Console.class.getName()); jaroslav@1230: jaroslav@1230: private Console() { jaroslav@1230: } jaroslav@1230: jaroslav@1230: static void register() { jaroslav@1230: registerImpl(new Console()); jaroslav@1230: } jaroslav@1230: jaroslav@1230: @JavaScriptBody(args = { "jconsole" }, body = jaroslav@1230: "console.log = function(m) { jconsole.log(m); };" + jaroslav@1230: "console.info = function(m) { jconsole.log(m); };" + jaroslav@1230: "console.error = function(m) { jconsole.log(m); };" + jaroslav@1230: "console.warn = function(m) { jconsole.log(m); };" jaroslav@1230: ) jaroslav@1230: private static native void registerImpl(Console c); jaroslav@1230: jaroslav@1230: public void log(String msg) { jaroslav@1230: LOG.info(msg); jaroslav@1230: } jaroslav@1230: }