12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- /*
- * Copyright 2008, Yahoo! Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package org.apache.zookeeper.server;
- import java.io.ByteArrayInputStream;
- import java.io.EOFException;
- import java.io.FileInputStream;
- import java.text.DateFormat;
- import java.util.Date;
- import org.apache.log4j.Logger;
- import org.apache.jute.BinaryInputArchive;
- import org.apache.jute.InputArchive;
- import org.apache.zookeeper.txn.TxnHeader;
- public class LogFormatter {
- private static final Logger LOG = Logger.getLogger(LogFormatter.class);
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception {
- if (args.length != 1) {
- System.err.println("USAGE: LogFormatter log_file");
- System.exit(2);
- }
- FileInputStream fis = new FileInputStream(args[0]);
- BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis);
- while (true) {
- byte[] bytes = logStream.readBuffer("txnEntry");
- if (bytes.length == 0) {
- // Since we preallocate, we define EOF to be an
- // empty transaction
- throw new EOFException();
- }
- InputArchive ia = BinaryInputArchive
- .getArchive(new ByteArrayInputStream(bytes));
- TxnHeader hdr = new TxnHeader();
- hdr.deserialize(ia, "hdr");
- System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT,
- DateFormat.LONG).format(new Date(hdr.getTime()))
- + " "
- + Long.toHexString(hdr.getClientId())
- + ":"
- + hdr.getCxid()
- + " "
- + Long.toHexString(hdr.getZxid())
- + " " + TraceFormatter.op2String(hdr.getType()));
- if (logStream.readByte("EOR") != 'B') {
- LOG.error("Last transaction was partial.");
- throw new EOFException();
- }
- }
- }
- }
|