提交 db8e3b78 编写于 作者: F Frankie Wu

local logview with hierarchy view

上级 70afdd80
......@@ -17,18 +17,19 @@ public class GsonTest {
Assert.assertEquals(expected, actual);
}
private Map<String, Pojo> mapOfPojo() {
Map<String, Pojo> map = new HashMap<String, Pojo>();
private Map<String, Object> map(Object forth) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("first", new Pojo(1, "x"));
map.put("second", new Pojo(2, "y"));
map.put("third", new Pojo(3, "z"));
map.put("forth", forth);
return map;
}
@Test
public void test() {
public void testSame() {
check(null, "");
check(1, "1");
check(1.2, "1.2");
......@@ -37,16 +38,19 @@ public class GsonTest {
check(new String[] { "x", "y" }, "[\"x\",\"y\"]");
check(new Pojo(3, null), "{\"x\":3}");
check(new Pojo(3, "a"), "{\"x\":3,\"y\":\"a\"}");
check(mapOfPojo(), "{\"second\":{\"x\":2,\"y\":\"y\"}," + //
"\"third\":{\"x\":3,\"y\":\"z\"}," + //
"\"first\":{\"x\":1,\"y\":\"x\"}}");
check(map(null),
"{\"second\":{\"x\":2,\"y\":\"y\"},\"third\":{\"x\":3,\"y\":\"z\"},\"first\":{\"x\":1,\"y\":\"x\"}}");
check(map(map(map(null))), //
"{\"forth\":{\"forth\":{\"second\":{\"x\":2,\"y\":\"y\"},\"third\":{\"x\":3,\"y\":\"z\"},\"first\":{\"x\":1,\"y\":\"x\"}},\"second\":{\"x\":2,\"y\":\"y\"},\"third\":{\"x\":3,\"y\":\"z\"},\"first\":{\"x\":1,\"y\":\"x\"}},\"second\":{\"x\":2,\"y\":\"y\"},\"third\":{\"x\":3,\"y\":\"z\"},\"first\":{\"x\":1,\"y\":\"x\"}}");
}
@Test
@Ignore
public void testOther() {
public void testNotSame() {
check(new Date(1330079278861L), "\"2012-02-24 18:27:58\"");
check(Date.class, "\"class java.util.Date\"");
check(new Object[] { "x", "y", new Object[] { 1, 2.3, true, map(null) } }, //
"[\"x\",\"y\",[1,2.3,true,{\"second\":{\"x\":2,\"y\":\"y\"},\"third\":{\"x\":3,\"y\":\"z\"},\"first\":{\"x\":1,\"y\":\"x\"}}]]");
}
public static class Pojo {
......
......@@ -130,7 +130,6 @@ public class Cat {
// this should be called when a thread ends to clean some thread local data
public static void reset() {
getInstance().m_initialized = false;
getInstance().m_manager.reset();
}
......
......@@ -6,6 +6,7 @@ import java.util.List;
import com.dianping.cat.message.MessageProducer;
import com.dianping.cat.message.internal.DefaultMessageManager;
import com.dianping.cat.message.internal.DefaultMessageProducer;
import com.dianping.cat.message.internal.MessageIdFactory;
import com.dianping.cat.message.io.DefaultTransportManager;
import com.dianping.cat.message.io.InMemoryQueue;
import com.dianping.cat.message.io.InMemoryReceiver;
......@@ -58,6 +59,8 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all.add(C(MessageManager.class, DefaultMessageManager.class));
all.add(C(MessageProducer.class, DefaultMessageProducer.class) //
.req(MessageManager.class));
all.add(C(MessageIdFactory.class) //
.req(MessageManager.class));
all.add(C(MessagePathBuilder.class, DefaultMessagePathBuilder.class) //
.req(MessageManager.class));
all.add(C(MessageStorage.class, "html", DefaultMessageStorage.class) //
......@@ -70,6 +73,7 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all.add(C(MessageCodec.class, "plain-text", PlainTextMessageCodec.class) //
.req(BufferWriter.class, "escape"));
all.add(C(MessageCodec.class, "html", HtmlMessageCodec.class) //
.req(MessagePathBuilder.class) //
.req(BufferWriter.class, "html-encode"));
all.add(C(MessageConsumer.class, DummyConsumer.ID, DummyConsumer.class));
......
......@@ -3,7 +3,6 @@ package com.dianping.cat.message.internal;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Stack;
import java.util.UUID;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
......@@ -20,6 +19,8 @@ import com.dianping.cat.message.spi.internal.DefaultMessageTree;
import com.site.lookup.ContainerHolder;
public class DefaultMessageManager extends ContainerHolder implements MessageManager, LogEnabled {
private MessageIdFactory m_factory;
private TransportManager m_manager;
// we don't use static modifier since MessageManager is a singleton in
......@@ -54,7 +55,7 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
@Override
public String createMessageId() {
return UUID.randomUUID().toString(); // TODO
return m_factory.getNextId();
}
@Override
......@@ -128,6 +129,10 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
}
m_manager = lookup(TransportManager.class);
m_factory = lookup(MessageIdFactory.class);
// initialize milli second resolution level timer
MilliSecondTimer.initialize();
}
@Override
......@@ -181,8 +186,8 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
if (m_stack.isEmpty()) {
MessageTree tree = m_tree.copy();
tree.setMessage(message);
tree.setMessageId(manager.createMessageId());
tree.setMessage(message);
manager.flush(tree);
} else {
Transaction entry = m_stack.peek();
......@@ -206,6 +211,7 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
if (m_stack.isEmpty()) {
MessageTree tree = m_tree.copy();
m_tree.setMessageId(null);
m_tree.setMessage(null);
manager.flush(tree);
}
......
package com.dianping.cat.message.internal;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import com.dianping.cat.message.spi.MessageManager;
import com.site.lookup.annotation.Inject;
public class MessageIdFactory implements Initializable {
@Inject
private MessageManager m_manager;
private long m_lastTimestamp = getTimestamp();
private volatile int m_index;
private String m_domain;
private String m_ipAddress;
public String getNextId() {
StringBuilder sb = new StringBuilder(40);
long timestamp = getTimestamp();
int index;
synchronized (this) {
if (timestamp != m_lastTimestamp) {
m_index = 0;
m_lastTimestamp = timestamp;
}
index = m_index++;
}
sb.append(m_domain); // in one machine, domain would not change
sb.append('-');
sb.append(m_ipAddress); // in one machine, ip address would not change
sb.append('-');
sb.append(Long.toHexString(timestamp));
sb.append('-');
sb.append(Integer.toHexString(index));
return sb.toString();
}
protected long getTimestamp() {
return MilliSecondTimer.currentTimeMillis();
}
@Override
public void initialize() throws InitializationException {
try {
m_domain = m_manager.getClientConfig().getApp().getDomain();
m_ipAddress = m_manager.getClientConfig().getApp().getIp();
} catch (Exception e) {
// ignore it
}
if (m_ipAddress == null) {
try {
byte[] bytes = InetAddress.getLocalHost().getAddress();
StringBuilder sb = new StringBuilder(bytes.length / 2);
for (byte b : bytes) {
sb.append(Integer.toHexString((b >> 4) & 0x0F));
sb.append(Integer.toHexString(b & 0x0F));
}
m_ipAddress = sb.toString();
} catch (UnknownHostException e) {
// ignore it
}
}
}
public void setDomain(String domain) {
m_domain = domain;
}
public void setIpAddress(String ipAddress) {
m_ipAddress = ipAddress;
}
}
package com.dianping.cat.message.spi;
public interface MessageId {
public String getDomain();
public long getTimestamp();
}
......@@ -11,4 +11,6 @@ public interface MessagePathBuilder {
public URL getLogViewBaseUrl();
public String getLogViewPath(MessageTree tree);
public String getLogViewPath(String messageId);
}
......@@ -15,6 +15,7 @@ import com.dianping.cat.message.Heartbeat;
import com.dianping.cat.message.Message;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.message.spi.MessageCodec;
import com.dianping.cat.message.spi.MessagePathBuilder;
import com.dianping.cat.message.spi.MessageTree;
import com.dianping.cat.message.spi.StringRope;
import com.site.lookup.annotation.Inject;
......@@ -30,12 +31,22 @@ public class HtmlMessageCodec implements MessageCodec {
private BufferWriter m_writer;
@Inject
private String m_logViewPrefix = "/cat/m/";
private MessagePathBuilder m_builder;
@Inject
private String m_logViewPrefix = "/cat/r/m/";
private BufferHelper m_bufferHelper = new BufferHelper(m_writer);
private DateHelper m_dateHelper = new DateHelper();
protected String buildLink(Message message) {
String messageId = message.getData().toString();
String path = m_builder.getLogViewPath(messageId);
return path;
}
@Override
public void decode(ChannelBuffer buf, MessageTree tree) {
throw new UnsupportedOperationException("HtmlMessageCodec only supported in one-way right now!");
......@@ -150,6 +161,28 @@ public class HtmlMessageCodec implements MessageCodec {
return count;
}
//<style>
//.nested {
//width:100%;
//display:none;
//}
//</style>
//
//<script>
//function show(a,id) {
// var cell = document.getElementById(id);
// var text = a.innerHTML;
//
// if (text == '[:: show ::]') {
// a.innerHTML = '[:: hide ::]';
// cell.src = "file:///Users/qmwu/project/tracking/cat-core/target/test.html";
// cell.style.display='block';
// } else {
// a.innerHTML = '[:: show ::]';
// cell.style.display='none';
// }
//}
//</script>
protected int encodeLogViewLink(Message message, ChannelBuffer buf, int level, LineCounter counter) {
BufferHelper helper = m_bufferHelper;
int count = 0;
......@@ -162,17 +195,17 @@ public class HtmlMessageCodec implements MessageCodec {
count += helper.tr1(buf, null);
}
String link = message.getData().toString();
String link = buildLink(message);
int id = Math.abs(link.hashCode());
count += helper.td1(buf);
count += helper.nbsp(buf, level * 2); // 2 spaces per level
count += helper.write(buf, String.format("<a href=\"%s%s\" onclick=\"show(%s);return false;\">[:: show ::]</a>",
count += helper.write(buf, String.format("<a href=\"%s%s\" onclick=\"return show(this,%s);\">[:: show ::]</a>",
m_logViewPrefix, link, id));
count += helper.td2(buf);
count += helper.td(buf, "", "colspan=\"4\" id=\"" + id + "\"");
count += helper.td(buf, "<div id=\"" + id + "\"></div>", "colspan=\"4\"");
count += helper.tr2(buf);
count += helper.crlf(buf);
......@@ -228,6 +261,10 @@ public class HtmlMessageCodec implements MessageCodec {
m_logViewPrefix = logViewPrefix;
}
public void setMessagePathBuilder(MessagePathBuilder builder) {
m_builder = builder;
}
protected static class BufferHelper {
private static byte[] TABLE1 = "<table class=\"logview\">".getBytes();
......
......@@ -6,7 +6,10 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.Date;
import java.util.List;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
......@@ -14,9 +17,10 @@ import com.dianping.cat.configuration.model.entity.Config;
import com.dianping.cat.message.spi.MessageManager;
import com.dianping.cat.message.spi.MessagePathBuilder;
import com.dianping.cat.message.spi.MessageTree;
import com.site.helper.Splitters;
import com.site.lookup.annotation.Inject;
public class DefaultMessagePathBuilder implements MessagePathBuilder, Initializable {
public class DefaultMessagePathBuilder implements MessagePathBuilder, Initializable, LogEnabled {
@Inject
private MessageManager m_manager;
......@@ -24,6 +28,8 @@ public class DefaultMessagePathBuilder implements MessagePathBuilder, Initializa
private URL m_baseLogUrl;
private Logger m_logger;
@Override
public String getHdfsPath(MessageTree tree, String host) {
MessageFormat format = new MessageFormat("{0,date,yyyyMMdd}/{0,date,HH}/{1}/{0,date,mm}-{2}");
......@@ -52,6 +58,26 @@ public class DefaultMessagePathBuilder implements MessagePathBuilder, Initializa
return path;
}
@Override
public String getLogViewPath(String messageId) {
List<String> parts = Splitters.by('-').split(messageId);
if (parts.size() == 4) {
try {
String domain = parts.get(0);
long timestamp = Long.parseLong(parts.get(2), 16);
MessageFormat format = new MessageFormat("{0,date,yyyyMMdd}/{0,date,HH}/{1}/{2}.html");
String path = format.format(new Object[] { new Date(timestamp), domain, messageId });
return path;
} catch (Exception e) {
m_logger.error("Invalid message id format: " + messageId, e);
}
}
return messageId;
}
@Override
public void initialize() throws InitializationException {
Config config = m_manager.getClientConfig();
......@@ -88,4 +114,9 @@ public class DefaultMessagePathBuilder implements MessagePathBuilder, Initializa
public void setBaseLogUrl(URL baseLogUrl) {
m_baseLogUrl = baseLogUrl;
}
@Override
public void enableLogging(Logger logger) {
m_logger = logger;
}
}
......@@ -37,6 +37,15 @@
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.message.internal.MessageIdFactory</role>
<implementation>com.dianping.cat.message.internal.MessageIdFactory</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.message.spi.MessageManager</role>
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.message.spi.MessagePathBuilder</role>
<implementation>com.dianping.cat.message.spi.internal.DefaultMessagePathBuilder</implementation>
......@@ -86,6 +95,9 @@
<role-hint>html</role-hint>
<implementation>com.dianping.cat.message.spi.codec.HtmlMessageCodec</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.message.spi.MessagePathBuilder</role>
</requirement>
<requirement>
<role>com.dianping.cat.message.spi.codec.BufferWriter</role>
<role-hint>html-encode</role-hint>
......
......@@ -5,6 +5,7 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import com.dianping.cat.message.configuration.ConfigTest;
import com.dianping.cat.message.internal.MessageIdFactoryTest;
import com.dianping.cat.message.internal.MessageProducerTest;
import com.dianping.cat.message.internal.MillisSecondTimerTest;
import com.dianping.cat.message.io.InMemoryTest;
......@@ -26,6 +27,8 @@ TransactionTest.class,
ConfigTest.class,
/* .internal */
MessageIdFactoryTest.class,
MessageProducerTest.class,
MillisSecondTimerTest.class,
......
package com.dianping.cat.message;
import static com.dianping.cat.message.Message.SUCCESS;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.dianping.cat.Cat;
import com.dianping.cat.message.spi.MessagePathBuilder;
@RunWith(JUnit4.class)
public class AppSimulator extends CatTestCase {
@Test
public void simulateHierarchyTransaction() throws Exception {
MessageProducer cat = Cat.getProducer();
Transaction t = cat.newTransaction("URL", "WebPage");
String id = Cat.getManager().getThreadLocalMessageTree().getMessageId();
String id1 = cat.createMessageId();
String id2 = cat.createMessageId();
try {
// do your business here
t.addData("k1", "v1");
t.addData("k2", "v2");
t.addData("k3", "v3");
Thread.sleep(5);
cat.logEvent("Type1", "Name1", SUCCESS, "data1");
cat.logEvent("Type2", "Name2", SUCCESS, "data2");
cat.logEvent("RemoteCall", "Service1", SUCCESS, id1);
createChildThreadTransaction(id1, cat.createMessageId(), cat.createMessageId());
cat.logEvent("Type3", "Name3", SUCCESS, "data3");
cat.logEvent("RemoteCall", "Service1", SUCCESS, id2);
createChildThreadTransaction(id2, cat.createMessageId(), cat.createMessageId(), cat.createMessageId());
cat.logEvent("Type4", "Name4", SUCCESS, "data4");
cat.logEvent("Type5", "Name5", SUCCESS, "data5");
t.setStatus(SUCCESS);
} catch (Exception e) {
t.setStatus(e);
} finally {
t.complete();
}
if (isCatServerAlive()) {
MessagePathBuilder builder = lookup(MessagePathBuilder.class);
System.out.println("Please open page http://localhost:2281/cat/r/m/" + builder.getLogViewPath(id));
} else {
System.out.println("CAT server is not started at localhost:2280, so no log view dumped!");
}
}
protected void createChildThreadTransaction(final String id, final String... childIds) {
Thread thread = new Thread() {
@Override
public void run() {
Cat.setup(null);
MessageProducer cat = Cat.getProducer();
Transaction t = cat.newTransaction("Service", "service-" + (int) (Math.random() * 10));
// override the message id
Cat.getManager().getThreadLocalMessageTree().setMessageId(id);
try {
// do your business here
t.addData("service data here");
Thread.sleep(5);
cat.logEvent("Type1", "Name1", SUCCESS, "data1");
cat.logEvent("Type2", "Name2", SUCCESS, "data2");
for (String childId : childIds) {
cat.logEvent("RemoteCall", "Service1", SUCCESS, childId);
createChildThreadTransaction(childId);
}
cat.logEvent("Type4", "Name4", SUCCESS, "data4");
cat.logEvent("Type5", "Name5", SUCCESS, "data5");
t.setStatus(SUCCESS);
} catch (Exception e) {
t.setStatus(e);
} finally {
t.complete();
Cat.reset();
}
}
};
thread.start();
// wait for it to complete
try {
thread.join();
} catch (InterruptedException e) {
// ignore it
}
}
}
package com.dianping.cat.message;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import org.junit.After;
import org.junit.Before;
import com.dianping.cat.Cat;
import com.dianping.cat.configuration.model.entity.App;
import com.dianping.cat.configuration.model.entity.Config;
import com.dianping.cat.configuration.model.entity.Server;
import com.site.helper.Files;
import com.site.lookup.ComponentTestCase;
public abstract class CatTestCase extends ComponentTestCase {
@Before
public void before() throws Exception {
Cat.initialize(getContainer(), null);
Cat.initialize(getContainer(), getConfigurationFile());
Cat.setup(null);
}
protected File getConfigurationFile() {
if (isCatServerAlive()) {
try {
Config config = new Config();
config.setMode("client");
config.setApp(new App().setDomain("Test"));
config.addServer(new Server().setIp("localhost").setPort(2280));
File file = new File("target/cat-config.xml");
Files.forIO().writeTo(file, config.toString());
return file;
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
protected boolean isCatServerAlive() {
// detect if a CAT server listens on localhost:2280
try {
SocketChannel channel = SocketChannel.open(new InetSocketAddress("localhost", 2280));
channel.close();
return true;
} catch (Exception e) {
// ignore it
}
return false;
}
@After
public void after() throws Exception {
Cat.reset();
......
package com.dianping.cat.message.internal;
import junit.framework.Assert;
import org.junit.Test;
public class MessageIdFactoryTest {
private long m_timestamp = 1330327814748L;
private MessageIdFactory m_factory = new MessageIdFactory() {
@Override
protected long getTimestamp() {
return m_timestamp;
}
};
@Test
public void test() throws Exception {
m_factory.initialize();
check("domain1", "domain1-c0a83f99-135bdb7825c-0");
check("domain1", "domain1-c0a83f99-135bdb7825c-1");
check("domain1", "domain1-c0a83f99-135bdb7825c-2");
check("domain1", "domain1-c0a83f99-135bdb7825c-3");
m_timestamp++;
check("domain1", "domain1-c0a83f99-135bdb7825d-0");
check("domain1", "domain1-c0a83f99-135bdb7825d-1");
check("domain1", "domain1-c0a83f99-135bdb7825d-2");
m_timestamp++;
check("domain1", "domain1-c0a83f99-135bdb7825e-0");
check("domain1", "domain1-c0a83f99-135bdb7825e-1");
check("domain1", "domain1-c0a83f99-135bdb7825e-2");
}
private void check(String domain, String expected) {
m_factory.setDomain(domain);
m_factory.setIpAddress("c0a83f99"); // 192.168.63.153
String actual = m_factory.getNextId();
Assert.assertEquals(expected, actual);
}
}
......@@ -17,6 +17,7 @@ import com.dianping.cat.message.internal.DefaultEvent;
import com.dianping.cat.message.internal.DefaultHeartbeat;
import com.dianping.cat.message.internal.DefaultTransaction;
import com.dianping.cat.message.spi.MessageTree;
import com.dianping.cat.message.spi.internal.DefaultMessagePathBuilder;
import com.dianping.cat.message.spi.internal.DefaultMessageTree;
public class HtmlMessageCodecTest {
......@@ -25,6 +26,7 @@ public class HtmlMessageCodecTest {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
codec.setBufferWriter(new HtmlEncodingBufferWriter());
codec.setMessagePathBuilder(new DefaultMessagePathBuilder());
codec.encodeMessage(message, buf, 0, null);
String actual = buf.toString(Charset.forName("utf-8"));
......@@ -36,6 +38,7 @@ public class HtmlMessageCodecTest {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
codec.setBufferWriter(new HtmlEncodingBufferWriter());
codec.setMessagePathBuilder(new DefaultMessagePathBuilder());
codec.encode(tree, buf);
buf.readInt(); // get rid of length
String actual = buf.toString(Charset.forName("utf-8"));
......@@ -174,8 +177,8 @@ public class HtmlMessageCodecTest {
root.addChild(newTransaction("Service", "Auth", timestamp, "0", 20, "userId=1357&token=..."));
root.addChild(newTransaction("Cache", "findReviewByPK", timestamp + 22, "Missing", 1, "2468") //
.addChild(newEvent("CacheHost", "host-1", timestamp + 22, "0", "ip=192.168.8.123")));
root.addChild(newEvent("Service", "ReviewService", timestamp + 23, "0", "message_id"));
root.addChild(newEvent("RemoteCall", "Pigeon", timestamp + 23, "0", "message_id"));
root.addChild(newEvent("Service", "ReviewService", timestamp + 23, "0", "request data"));
root.addChild(newEvent("RemoteCall", "Pigeon", timestamp + 23, "0", "domain1-c0a83f99-135bdb7825c-1"));
root.addChild(newTransaction("DAL", "findReviewByPK", timestamp + 25, "0", 5,
"select title,content from Review where id = ?"));
root.addChild(newEvent("URL", "View", timestamp + 40, "0", "view=HTML"));
......@@ -187,8 +190,8 @@ public class HtmlMessageCodecTest {
+ "<tr><td>&nbsp;&nbsp;t15:33:42.009</td><td>Cache</td><td>findReviewByPK</td><td></td><td></td></tr>\r\n"
+ "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;E15:33:42.009</td><td>CacheHost</td><td>host-1</td><td>0</td><td>ip=192.168.8.123</td></tr>\r\n"
+ "<tr><td>&nbsp;&nbsp;T15:33:42.010</td><td>Cache</td><td>findReviewByPK</td><td class=\"error\">Missing</td><td>1ms 2468</td></tr>\r\n"
+ "<tr><td>&nbsp;&nbsp;E15:33:42.010</td><td>Service</td><td>ReviewService</td><td>0</td><td>message_id</td></tr>\r\n"
+ "<tr><td>&nbsp;&nbsp;<a href=\"/cat/m/message_id\" onclick=\"show(1690722221);return false;\">[:: show ::]</a></td><td colspan=\"4\" id=\"1690722221\"></td></tr>\r\n"
+ "<tr><td>&nbsp;&nbsp;E15:33:42.010</td><td>Service</td><td>ReviewService</td><td>0</td><td>request data</td></tr>\r\n"
+ "<tr><td>&nbsp;&nbsp;<a href=\"/cat/m/20120227/15/domain1/domain1-c0a83f99-135bdb7825c-1.html\" onclick=\"show(this,1677274581);return false;\">[:: show ::]</a></td><td colspan=\"4\"><div id=\"1677274581\"></div></td></tr>\r\n"
+ "<tr><td>&nbsp;&nbsp;A15:33:42.012</td><td>DAL</td><td>findReviewByPK</td><td>0</td><td>5ms select title,content from Review where id = ?</td></tr>\r\n"
+ "<tr><td>&nbsp;&nbsp;E15:33:42.027</td><td>URL</td><td>View</td><td>0</td><td>view=HTML</td></tr>\r\n"
+ "<tr><td>T15:33:42.087</td><td>URL</td><td>Review</td><td>0</td><td>100ms /review/2468</td></tr>\r\n");
......
package com.dianping.cat.report.page.logview;
public enum JspFile {
VIEW("/jsp/report/logview.jsp"),
LOGVIEW("/jsp/report/logview.jsp"),
LOGVIEW_NO_HEADER("/jsp/report/logview_bare.jsp"),
;
......
......@@ -7,10 +7,15 @@ public class JspViewer extends BaseJspViewer<ReportPage, Action, Context, Model>
@Override
protected String getJspFilePath(Context ctx, Model model) {
Action action = model.getAction();
Payload payload = ctx.getPayload();
switch (action) {
case VIEW:
return JspFile.VIEW.getPath();
if (payload.isShowHeader()) {
return JspFile.LOGVIEW.getPath();
} else {
return JspFile.LOGVIEW_NO_HEADER.getPath();
}
}
throw new RuntimeException("Unknown action: " + action);
......
......@@ -12,40 +12,43 @@ public class Payload implements ActionPayload<ReportPage, Action> {
@FieldMeta("op")
private Action m_action;
@FieldMeta("header")
private boolean m_showHeader = true;
@FieldMeta("id")
private int m_identifier;
@PathMeta("path")
private String[] m_path;
public void setAction(Action action) {
m_action = action;
@Override
public Action getAction() {
return m_action;
}
public int getIdentifier() {
return m_identifier;
}
public void setIdentifier(int identifier) {
m_identifier = identifier;
}
@Override
public Action getAction() {
return m_action;
public ReportPage getPage() {
return m_page;
}
public String[] getPath() {
return m_path;
}
public void setPath(String[] path) {
m_path = path;
public boolean isShowHeader() {
return m_showHeader;
}
@Override
public ReportPage getPage() {
return m_page;
public void setAction(Action action) {
m_action = action;
}
public void setIdentifier(int identifier) {
m_identifier = identifier;
}
@Override
......@@ -53,6 +56,14 @@ public class Payload implements ActionPayload<ReportPage, Action> {
m_page = ReportPage.getByName(page, ReportPage.LOGVIEW);
}
public void setPath(String[] path) {
m_path = path;
}
public void setShowHeader(String showHeader) {
m_showHeader = !"no".equals(showHeader);
}
@Override
public void validate(ActionContext<?> ctx) {
}
......
......@@ -51,6 +51,13 @@
<tag-class>org.unidal.webres.taglib.basic.UseCssTagHandler</tag-class>
<body-content>JSP</body-content>
<attribute>
<description><![CDATA[Set the css value with EL or a css ref.]]></description>
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
</attribute>
<attribute>
<description><![CDATA[Identify whether the link URL is secure or not.]]></description>
<name>secure</name>
<required>false</required>
......@@ -72,13 +79,6 @@
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Set the css value with EL or a css ref.]]></description>
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
</attribute>
<attribute>
<description><![CDATA[Target placement for this css resource to render]]></description>
<name>target</name>
<required>false</required>
......@@ -114,18 +114,18 @@
<tag-class>org.unidal.webres.taglib.basic.SetTagHandler</tag-class>
<body-content>JSP</body-content>
<attribute>
<description><![CDATA[The name.]]></description>
<name>id</name>
<description><![CDATA[The value]]></description>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
<type>java.lang.Object</type>
</attribute>
<attribute>
<description><![CDATA[The value]]></description>
<name>value</name>
<description><![CDATA[The name.]]></description>
<name>id</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
<type>java.lang.String</type>
</attribute>
<dynamic-attributes>false</dynamic-attributes>
</tag>
......@@ -135,6 +135,13 @@
<tag-class>org.unidal.webres.taglib.basic.UseJsTagHandler</tag-class>
<body-content>JSP</body-content>
<attribute>
<description><![CDATA[Set the js value with EL or a js ref.]]></description>
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
</attribute>
<attribute>
<description><![CDATA[Identify whether the link URL is secure or not.]]></description>
<name>secure</name>
<required>false</required>
......@@ -156,13 +163,6 @@
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Set the js value with EL or a js ref.]]></description>
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
</attribute>
<attribute>
<description><![CDATA[Target placement for this js resource to render]]></description>
<name>target</name>
<required>false</required>
......@@ -177,6 +177,13 @@
<tag-class>org.unidal.webres.taglib.basic.LinkTagHandler</tag-class>
<body-content>JSP</body-content>
<attribute>
<description><![CDATA[The value for link, could be a expression or a link ref.]]></description>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
</attribute>
<attribute>
<description><![CDATA[Identify whether the link URL is secure or not.]]></description>
<name>secure</name>
<required>false</required>
......@@ -190,13 +197,6 @@
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[The value for link, could be a expression or a link ref.]]></description>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
</attribute>
<dynamic-attributes>true</dynamic-attributes>
</tag>
<tag>
......@@ -205,6 +205,13 @@
<tag-class>org.unidal.webres.taglib.basic.ImageTagHandler</tag-class>
<body-content>JSP</body-content>
<attribute>
<description><![CDATA[The value for image, could be a expression or a image path.]]></description>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
</attribute>
<attribute>
<description><![CDATA[Identify whether the image URL is secure or not.]]></description>
<name>secure</name>
<required>false</required>
......@@ -225,13 +232,6 @@
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[The value for image, could be a expression or a image path.]]></description>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
</attribute>
<dynamic-attributes>true</dynamic-attributes>
</tag>
<tag>
......
.logview {
width: auto;
}
tr.odd td {
background-color: #eee;
font-size: small;
......@@ -18,4 +22,4 @@ tr.even td {
.error {
color: red;
}
\ No newline at end of file
}
此差异已折叠。
function show(anchor, id) {
var cell = document.getElementById(id);
var text = anchor.innerHTML;
if (text == '[:: show ::]') {
anchor.innerHTML = '[:: hide ::]';
$.ajax({
type: "get",
url: anchor.href + "?header=no",
success : function(data, textStatus) {
cell.innerHTML = data;
}
});
cell.style.display = 'block';
} else {
anchor.innerHTML = '[:: show ::]';
cell.style.display = 'none';
}
return false;
}
\ No newline at end of file
......@@ -6,9 +6,13 @@
<jsp:useBean id="payload" type="com.dianping.cat.report.page.logview.Payload" scope="request"/>
<jsp:useBean id="model" type="com.dianping.cat.report.page.logview.Model" scope="request"/>
<res:useCss value='${res.css.local.default_css}' target="head-css" />
<res:useCss value='${res.css.local.style_css}' target="head-css" />
<res:useCss value='${res.css.local.logview_css}' target="head-css"/>
<res:useCss value="${res.css.local.default_css}" target="head-css" />
<res:useCss value="${res.css.local.style_css}" target="head-css" />
<res:useCss value="${res.css.local.logview_css}" target="head-css"/>
<res:useJs value="${res.js.local['jquery-1.7.1.js']}" target="head-js"/>
<res:useJs value="${res.js.local.logview_js}" target="head-js"/>
<a:body>
<c:choose>
......
<%@ page contentType="text/html; charset=utf-8"%>
${model.table}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册