Siobhan Tully | e18b344 | 2014-02-23 14:23:34 -0500 | [diff] [blame] | 1 | <?xml version="1.0"?>
|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
| 4 | <head>
|
| 5 | <title>log4javascript in-page console demo</title>
|
| 6 | <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
|
| 7 | <meta name="author" content="Tim Down - tim@log4javascript.org" />
|
| 8 | <meta name="description" content="log4javascript, a logging framework for JavaScript based on log4j" />
|
| 9 | <meta name="robots" content="all" />
|
| 10 | <link rel="stylesheet" type="text/css" media="screen,print" href="../main.css" title="Default" />
|
| 11 | <script type="text/javascript" src="../js/log4javascript_uncompressed.js"></script>
|
| 12 | <script type="text/javascript">
|
| 13 | // <![CDATA[
|
| 14 | var log = log4javascript.getLogger("main");
|
| 15 | var appender = new log4javascript.InPageAppender();
|
| 16 | log.addAppender(appender);
|
| 17 | log.debug("This is a debugging message from the log4javascript in-page page");
|
| 18 |
|
| 19 | var words = ["Watford", "eased", "their", "relegation", "fears", "with", "a", "win",
|
| 20 | "against", "a", "Charlton", "side", "who", "slipped", "further", "towards", "the",
|
| 21 | "drop", "Don", "Cowie", "drilled", "in", "a", "shot", "to", "put", "the", "Hornets",
|
| 22 | "ahead", "before", "Tresor", "Kandol", "ended", "a", "powerful", "run", "by",
|
| 23 | "rounding", "keeper", "Scott", "Loach", "and", "slotting", "in", "to", "level"
|
| 24 | ];
|
| 25 |
|
| 26 | var loaded = false;
|
| 27 |
|
| 28 | function generateRandom() {
|
| 29 | var numberOfEntries = parseInt(document.getElementById("numberOfLogEntries").value);
|
| 30 | for (var i = 0; i < numberOfEntries; i++) {
|
| 31 | var numberOfWords = 1 + Math.floor(10 * Math.random());
|
| 32 | var entryWords = [];
|
| 33 | for (var j = 0; j < numberOfWords; j++) {
|
| 34 | entryWords.push(words[Math.floor(Math.random() * words.length)]);
|
| 35 | }
|
| 36 | var entryMessage = entryWords.join(" ");
|
| 37 | var levelNum = Math.floor(Math.random() * 6);
|
| 38 | switch (levelNum) {
|
| 39 | case 0:
|
| 40 | log.trace(entryMessage);
|
| 41 | break;
|
| 42 | case 1:
|
| 43 | log.debug(entryMessage);
|
| 44 | break;
|
| 45 | case 2:
|
| 46 | log.info(entryMessage);
|
| 47 | break;
|
| 48 | case 3:
|
| 49 | log.warn(entryMessage);
|
| 50 | break;
|
| 51 | case 4:
|
| 52 | log.error(entryMessage);
|
| 53 | break;
|
| 54 | case 5:
|
| 55 | log.fatal(entryMessage);
|
| 56 | break;
|
| 57 | }
|
| 58 | }
|
| 59 | }
|
| 60 |
|
| 61 | var consoleVisible = true;
|
| 62 |
|
| 63 | function toggleConsole(button) {
|
| 64 | if (consoleVisible) {
|
| 65 | appender.hide();
|
| 66 | button.value = "Show console";
|
| 67 | consoleVisible = false;
|
| 68 | } else {
|
| 69 | appender.show();
|
| 70 | button.value = "Hide console";
|
| 71 | consoleVisible = true;
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | function generateObjectExpansion() {
|
| 76 | var debugObj = {
|
| 77 | a: {
|
| 78 | b: "stuff",
|
| 79 | c: 3,
|
| 80 | d: {
|
| 81 | e: ["a", "b", "c"]
|
| 82 | }
|
| 83 | },
|
| 84 | f: "Things",
|
| 85 | g: 5
|
| 86 | };
|
| 87 | log.debug(debugObj);
|
| 88 | }
|
| 89 |
|
| 90 | function generateError() {
|
| 91 | try {
|
| 92 | throw new Error("Made up error");
|
| 93 | } catch (ex) {
|
| 94 | log.error("Logging an error!", ex);
|
| 95 | }
|
| 96 | }
|
| 97 | // ]]>
|
| 98 | </script>
|
| 99 | </head>
|
| 100 | <body>
|
| 101 | <div id="container" class="nonav">
|
| 102 | <div id="header">
|
| 103 | <h1><a href="/docs/index.html">log4javascript</a></h1>
|
| 104 | </div>
|
| 105 | <div id="content">
|
| 106 | <div id="nav">
|
| 107 | <a class="navitem" href="../index.html">home</a>
|
| 108 | | <a class="navitem" href="http://sourceforge.net/projects/log4javascript" target="_blank" title="Download (opens in new window)">download</a>
|
| 109 | | <a class="navitem" href="../docs/index.html">docs</a>
|
| 110 | | <a class="navitem" href="../docs/quickstart.html">quick start</a>
|
| 111 | | <a class="navitem" href="index.html">demos</a>
|
| 112 | | <a class="navitem" href="http://log4javascript.org" target="_blank">website</a>
|
| 113 | | <a class="navitem" href="http://www.timdown.co.uk" target="_blank">timdown.co.uk</a>
|
| 114 | </div>
|
| 115 | <h1>log4javascript in-page console demo</h1>
|
| 116 | <p>
|
| 117 | This demo demonstrates an in-page logger. The example uses the default behaviour, which
|
| 118 | is to place the log console in a fixed area at the bottom of the page. However, the
|
| 119 | console may be placed inside any element in the page. To do this, you may specify the ID
|
| 120 | of the element (even if the page has not yet loaded) or a reference to the element itself.
|
| 121 | </p>
|
| 122 | <p>
|
| 123 | Enter a log message below and click on one of the buttons to log
|
| 124 | your message at your desired level. You can then filter by
|
| 125 | log level, toggle word-wrapping and perform text and regular
|
| 126 | expression searches on the log entries.
|
| 127 | </p>
|
| 128 | <div class="example">
|
| 129 | <input type="button" value="Hide console" onclick="toggleConsole(this)" />
|
| 130 | <br />
|
| 131 | <input type="text" id="logText" value="Put log message here" />
|
| 132 | <input type="button" value="debug" onclick="log.debug(document.getElementById('logText').value)" />
|
| 133 | <input type="button" value="info" onclick="log.info(document.getElementById('logText').value)" />
|
| 134 | <input type="button" value="warn" onclick="log.warn(document.getElementById('logText').value)" />
|
| 135 | <input type="button" value="error" onclick="log.error(document.getElementById('logText').value)" />
|
| 136 | <input type="button" value="fatal" onclick="log.fatal(document.getElementById('logText').value)" />
|
| 137 | <br />
|
| 138 | <input type="button" value="assert 1 equals 1" onclick="log.assert(1 === 1)" />
|
| 139 | <input type="button" value="assert 1 equals 2" onclick="log.assert(1 === 2)" />
|
| 140 | <br />
|
| 141 | Generate <input type="text" size="5" id="numberOfLogEntries" value="50" /> random log entries
|
| 142 | <input type="button" value="go" onclick="generateRandom()" />
|
| 143 | <br />
|
| 144 | <input type="button" value="Log exception" onclick="generateError()" />
|
| 145 | <input type="button" value="Log example object" onclick="generateObjectExpansion()" />
|
| 146 | <br />
|
| 147 | <input type="checkbox" id="enabled" onclick="log4javascript.setEnabled(this.checked)" checked="checked" /> <label for="enabled">logging enabled</label>
|
| 148 | <br />
|
| 149 | <input type="text" id="groupName" value="Group name" />
|
| 150 | <input type="button" value="group" onclick="log.group(document.getElementById('groupName').value)" />
|
| 151 | <input type="button" value="end group" onclick="log.groupEnd()" />
|
| 152 | <br />
|
| 153 | <input type="text" id="timerName" value="Example timer name" />
|
| 154 | <input type="button" value="start timer" onclick="log.time(document.getElementById('timerName').value)" />
|
| 155 | <input type="button" value="end timer" onclick="log.timeEnd(document.getElementById('timerName').value)" />
|
| 156 | </div>
|
| 157 | </div>
|
| 158 | <br class="clear" />
|
| 159 | <div id="log"></div>
|
| 160 | <div id="footer">
|
| 161 | <span class="externallinkinfo">
|
| 162 | <strong>NB.</strong> All external links open in a new window.
|
| 163 | </span>
|
| 164 | Written by Tim Down. <a href="mailto:tim@log4javascript.org">tim@log4javascript.org</a>
|
| 165 | <br />
|
| 166 | log4javascript is distributed under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html"
|
| 167 | title="Apache License, Version 2.0 (opens in new window)" target="_blank">Apache License,
|
| 168 | Version 2.0</a>
|
| 169 |
|
| 170 | </div>
|
| 171 | </div>
|
| 172 |
|
| 173 | </body>
|
| 174 | </html>
|