001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.rest.logger; 018 019import static java.util.logging.Level.*; 020import static org.apache.juneau.rest.logger.CallLoggingDetail.*; 021 022import org.apache.juneau.cp.*; 023import org.apache.juneau.rest.*; 024 025/** 026 * Basic implementation of a call logger. 027 * 028 * <h5 class='section'>Configured Settings:</h5> 029 * <ul> 030 * <li>Logs to the {@link RestContext#getLogger() context logger}. 031 * <li>Only calls with status code >=400 will be logged. 032 * <li>Logs full request and response entity. 033 * </ul> 034 * 035 * <h5 class='section'>See Also:</h5><ul> 036 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerLoggingAndDebugging">Logging / Debugging</a> 037 * </ul> 038 */ 039public class BasicCallLogger extends CallLogger { 040 041 /** 042 * Constructor using specific settings. 043 * 044 * @param beanStore The bean store containing injectable beans for this logger. 045 */ 046 public BasicCallLogger(BeanStore beanStore) { 047 super(beanStore); 048 } 049 050 /** 051 * Constructor using default settings. 052 * <p> 053 * Uses the same settings as {@link CallLogger}. 054 */ 055 public BasicCallLogger() { 056 super(BeanStore.INSTANCE); 057 } 058 059 @Override 060 protected Builder init(BeanStore beanStore) { 061 return super.init(beanStore) 062 .normalRules( // Rules when debugging is not enabled. 063 CallLoggerRule.create(beanStore) // Log 500+ errors with status-line and header information. 064 .statusFilter(x -> x >= 500) 065 .level(SEVERE) 066 .requestDetail(HEADER) 067 .responseDetail(HEADER) 068 .build(), 069 CallLoggerRule.create(beanStore) // Log 400-500 errors with just status-line information. 070 .statusFilter(x -> x >= 400) 071 .level(WARNING) 072 .requestDetail(STATUS_LINE) 073 .responseDetail(STATUS_LINE) 074 .build() 075 ) 076 .debugRules( // Rules when debugging is enabled. 077 CallLoggerRule.create(beanStore) // Log everything with full details. 078 .level(SEVERE) 079 .requestDetail(ENTITY) 080 .responseDetail(ENTITY) 081 .build() 082 ) 083 ; 084 } 085}