private void writeEvent(HiveHookEventProtoPartialBuilder builder) {
      HiveHookEventProto event = builder.build();
      for (int retryCount = 0; retryCount <= MAX_RETRIES; ++retryCount) {
        try {
          if (eventPerFile) {
            if (writer != null) {
              IOUtils.closeQuietly(writer);
            }
            writer = logger.getWriter(logFileName + "_" + ++logFileCount);
            LOG.debug("Event per file enabled. New proto event file: {}", writer.getPath());
            writer.writeProto(event);
            IOUtils.closeQuietly(writer);
            writer = null;
          } else {
            maybeRolloverWriterForDay();
            writer.writeProto(event);
            writer.hflush();
          }
          return;
        } catch (IOException e) {
          // Something wrong with writer, lets close and reopen.
          IOUtils.closeQuietly(writer);
          writer = null;
          if (retryCount < MAX_RETRIES) {
            LOG.warn("Error writing proto message for query {}, eventType: {}, retryCount: {}," +
                " error: {} ", event.getHiveQueryId(), event.getEventType(), retryCount,
                e.getMessage(), e);
            LOG.trace("Exception", e);
          } else {
            LOG.error("Error writing proto message for query {}, eventType: {}: ",
                event.getHiveQueryId(), event.getEventType(), e);
          }
          try {
            // 0 seconds, for first retry assuming fs object was closed and open will fix it.
            Thread.sleep(1000 * retryCount * retryCount);
          } catch (InterruptedException e1) {
            LOG.warn("Got interrupted in retry sleep.", e1);
          }
        }
      }
    }
Log events from hive hook using protobuf serialized format, partitioned by date.
ql/src/java/org/apache/hadoop/hive/ql/hooks/HiveProtoLoggingHook.java