LCOV - code coverage report
Current view: top level - pgm/http/jetty - HttpLogJsonLayout.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 0 20 0.0 %
Date: 2022-11-19 15:00:39 Functions: 0 3 0.0 %

          Line data    Source code
       1             : // Copyright (C) 2020 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.pgm.http.jetty;
      16             : 
      17             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_COMMAND_STATUS;
      18             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_CONTENT_LENGTH;
      19             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_CPU_TOTAL;
      20             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_CPU_USER;
      21             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_HOST;
      22             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_LATENCY;
      23             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_MEMORY;
      24             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_METHOD;
      25             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_PROTOCOL;
      26             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_REFERER;
      27             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_RESOURCE;
      28             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_STATUS;
      29             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_USER;
      30             : import static com.google.gerrit.pgm.http.jetty.HttpLog.P_USER_AGENT;
      31             : 
      32             : import com.google.gerrit.util.logging.JsonLayout;
      33             : import com.google.gerrit.util.logging.JsonLogEntry;
      34             : import org.apache.log4j.spi.LoggingEvent;
      35             : 
      36           0 : public class HttpLogJsonLayout extends JsonLayout {
      37             : 
      38             :   @Override
      39             :   public JsonLogEntry toJsonLogEntry(LoggingEvent event) {
      40           0 :     return new HttpJsonLogEntry(event);
      41             :   }
      42             : 
      43             :   @SuppressWarnings("unused")
      44             :   private class HttpJsonLogEntry extends JsonLogEntry {
      45             :     public String host;
      46             :     public String thread;
      47             :     public String user;
      48             :     public String timestamp;
      49             :     public String method;
      50             :     public String resource;
      51             :     public String protocol;
      52             :     public String status;
      53             :     public String contentLength;
      54             :     public String latency;
      55             :     public String cpuTotal;
      56             :     public String cpuUser;
      57             :     public String memory;
      58             :     public String referer;
      59             :     public String userAgent;
      60             :     public String commandStatus;
      61             : 
      62           0 :     public HttpJsonLogEntry(LoggingEvent event) {
      63           0 :       this.host = getMdcString(event, P_HOST);
      64           0 :       this.thread = event.getThreadName();
      65           0 :       this.user = getMdcString(event, P_USER);
      66           0 :       this.timestamp = timestampFormatter.format(event.getTimeStamp());
      67           0 :       this.method = getMdcString(event, P_METHOD);
      68           0 :       this.resource = getMdcString(event, P_RESOURCE);
      69           0 :       this.protocol = getMdcString(event, P_PROTOCOL);
      70           0 :       this.status = getMdcString(event, P_STATUS);
      71           0 :       this.contentLength = getMdcString(event, P_CONTENT_LENGTH);
      72           0 :       this.latency = getMdcString(event, P_LATENCY);
      73           0 :       this.cpuTotal = getMdcString(event, P_CPU_TOTAL);
      74           0 :       this.cpuUser = getMdcString(event, P_CPU_USER);
      75           0 :       this.memory = getMdcString(event, P_MEMORY);
      76           0 :       this.referer = getMdcString(event, P_REFERER);
      77           0 :       this.userAgent = getMdcString(event, P_USER_AGENT);
      78           0 :       this.commandStatus = getMdcString(event, P_COMMAND_STATUS);
      79           0 :     }
      80             :   }
      81             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750