litesoft
@ 948
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.client.logging; import org.litesoft.GWT.client.*; import org.litesoft.commonfoundation.typeutils.*; import org.litesoft.logger.*; import org.litesoft.logger.nonpublic.*; import com.google.gwt.user.client.*; public class BrowserAsLogSyncFactory implements ProxyLoggerFactory { public static final int MAX_LOG_LINES_TO_CACHE = 100; public static final BrowserAsLogSyncFactory INSTANCE = new BrowserAsLogSyncFactory(); public static final Command COMMAND = new Command() { @Override public void execute() { BrowserAsLogSyncFactory.open(); } }; private BrowserAsLogSyncFactory() { } public static void open() { if ( (sOpen = openLogSyncBrowser( UtilsGwt.CHROMELESS_SCROLLED, CLIENT_LOGGING_HTML )) ) { sOpen = addToLogSyncBrowser( "" ); while ( sOpen && sSavedLines.hasLines() ) { if ( (sOpen = addToLogSyncBrowser( sSavedLines.peekLine() )) ) { sSavedLines.dropLine(); } } } } public static void log( String pText ) { if ( sOpen ) { if ( addToLogSyncBrowser( pText ) ) { return; } sOpen = false; } sSavedLines.add( pText ); } private static LogLinkedList sSavedLines = new LogLinkedList(); private static boolean sOpen = false; public static native boolean openLogSyncBrowser( String pFeatures, String pHTML ) /*-{ $wnd.loggingWindow = $wnd.open( "", "", pFeatures ); if ( !$wnd.loggingWindow ) { return false; } $wnd.loggingWindow.document.write( pHTML ); $wnd.loggingWindow.document.close(); return true; }-*/; public static native boolean addToLogSyncBrowser( String pText )/*-{ if ( $wnd.loggingWindow ) { try { var zThierLog = $wnd.loggingWindow.appendToLog; if ( zThierLog ) { zThierLog( pText ); return true; } } catch ( e ) { } $wnd.loggingWindow = null; } return false; }-*/; private static class LogLinkedList { private int mNodes = 0; private Node mHead = null; private Node mTail = null; public boolean hasLines() { return (mNodes != 0); } public String peekLine() { return (mHead != null) ? mHead.getText() : null; } public void dropLine() { if ( hasLines() ) { mNodes--; if ( null == (mHead = mHead.getNext()) ) { mTail = null; } } } public void add( String pText ) { if ( mTail == null ) { mHead = mTail = new Node( pText ); } else { mTail = mTail.add( pText ); } if ( ++mNodes > MAX_LOG_LINES_TO_CACHE ) { mNodes--; mHead = mHead.getNext(); } } private static class Node { private Node mNext = null; private String mText; public Node( String pText ) { mText = pText; } public Node getNext() { return mNext; } public String getText() { return mText; } public Node add( String pText ) { return mNext = new Node( pText ); } } } private static final String CLIENT_LOGGING_HTML = "<html><head><title>Client Side Log</title><script>\n" + // "function appendToLog( pLogEntry )\n" + // "{\n" + // " var myBody = document.body;\n" + // " var preNode = document.createElement( 'pre' );\n" + // " preNode.style.margin = '0';\n" + // " myBody.appendChild( preNode );\n" + // " var txtNode = document.createTextNode( pLogEntry );\n" + // " preNode.appendChild( txtNode );\n" + // " document.close();\n" + // "}\n" + // "</script></head><body style='margin:0; padding:0;'>" + // "<center>Client Side Logging<br>" + // "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " + "- - - - - -" + "</center></body></html>"; @Override public ImplLoggerAdapter createImplLoggerAdapter( int pLevel, String pClassname ) { return new Logger( pLevel, pClassname ); } private static class Logger extends SystemOutLoggerAdapter { public Logger( int pLevel, String pClassname ) { super( LoggerLevel.LEVELS[pLevel], pClassname ); } @Override protected void println( Throwable pThrowable ) { super.println( pThrowable ); BrowserAsLogSyncFactory.log( Throwables.printStackTraceToString( pThrowable ) ); } @Override protected void println( boolean pHasThrowable, String pText ) { super.println( pHasThrowable, pText ); BrowserAsLogSyncFactory.log( pText ); } } } |
Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/logging/BrowserAsLogSyncFactory.java
Revision | Author | Commited | Message |
---|---|---|---|
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
822 Diff | GeorgeS | Sun 19 Aug, 2012 01:03:51 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
23 Diff | GeorgeS | Wed 24 Feb, 2010 00:34:32 +0000 | |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |