LogAdvice.java |
1 /** 2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved. 3 * 4 * The contents of this file are subject to the terms of the Liferay Enterprise 5 * Subscription License ("License"). You may not use this file except in 6 * compliance with the License. You can obtain a copy of the License by 7 * contacting Liferay, Inc. See the License for the specific language governing 8 * permissions and limitations under the License, including but not limited to 9 * distribution rights of the Software. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 * SOFTWARE. 18 */ 19 20 /** 21 * The contents of this file are subject to the terms of the Common Development 22 * and Distribution License (the License). You may not use this file except in 23 * compliance with the License. 24 * 25 * You can obtain a copy of the License at http://www.sun.com/cddl/cddl.html and 26 * legal/CDDLv1.0.txt. See the License for the specific language governing 27 * permission and limitations under the License. 28 * 29 * When distributing Covered Code, include this CDDL Header Notice in each file 30 * and include the License file at legal/CDDLv1.0.txt. 31 * 32 * If applicable, add the following below the CDDL Header, with the fields 33 * enclosed by brackets [] replaced by your own identifying information: 34 * "Portions Copyrighted [year] [name of copyright owner]" 35 * 36 * Copyright 2009 Sun Microsystems Inc. All rights reserved. 37 */ 38 39 package com.liferay.portal.spring.aop; 40 41 import com.liferay.portal.kernel.log.Log; 42 import com.liferay.portal.kernel.log.LogFactoryUtil; 43 44 import java.util.HashMap; 45 import java.util.Map; 46 47 import org.aspectj.lang.ProceedingJoinPoint; 48 49 /** 50 * <a href="LogAdvice.java.html"><b><i>View Source</i></b></a> 51 * 52 * @author Karthik Sudarshan 53 * @author Brian Wing Shun Chan 54 * @author Michael Young 55 * 56 */ 57 public class LogAdvice { 58 59 public Object invoke(ProceedingJoinPoint proceedingJoinPoint) 60 throws Throwable { 61 62 String typeName = proceedingJoinPoint.getTarget().getClass().getName(); 63 64 Log log = getLog(typeName); 65 66 if (log.isInfoEnabled()) { 67 log.info("Before " + typeName); 68 } 69 70 Object returnVal = proceedingJoinPoint.proceed(); 71 72 if (log.isInfoEnabled()) { 73 log.info("After " + typeName); 74 } 75 76 return returnVal; 77 } 78 79 protected Log getLog(String typeName) { 80 Log log = _logs.get(typeName); 81 82 if (log == null) { 83 log = LogFactoryUtil.getLog(typeName); 84 85 _logs.put(typeName, log); 86 } 87 88 return log; 89 } 90 91 private static Map<String, Log> _logs = new HashMap<String, Log>(); 92 93 }