001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2014 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * SonarQube is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.api.utils.log; 021 022import javax.annotation.Nullable; 023 024/** 025 * 026 * @since 5.1 027 */ 028public abstract class Profiler { 029 030 public static Profiler create(Logger logger) { 031 return new DefaultProfiler((BaseLogger) logger); 032 } 033 034 public static Profiler createIfTrace(Logger logger) { 035 if (logger.isTraceEnabled()) { 036 return create(logger); 037 } 038 return NullProfiler.NULL_INSTANCE; 039 } 040 041 public static Profiler createIfDebug(Logger logger) { 042 if (logger.isDebugEnabled()) { 043 return create(logger); 044 } 045 return NullProfiler.NULL_INSTANCE; 046 } 047 048 public abstract boolean isDebugEnabled(); 049 050 public abstract boolean isTraceEnabled(); 051 052 public abstract Profiler start(); 053 054 public abstract Profiler startTrace(String message); 055 056 public abstract Profiler startDebug(String message); 057 058 public abstract Profiler startInfo(String message); 059 060 /** 061 * Works only if a message have been set in startXXX() methods. 062 */ 063 public abstract Profiler stopTrace(); 064 065 public abstract Profiler stopDebug(); 066 067 public abstract Profiler stopInfo(); 068 069 public abstract Profiler stopTrace(String message); 070 071 public abstract Profiler stopDebug(String message); 072 073 public abstract Profiler stopInfo(String message); 074 075 /** 076 * Context information is removed if value is <code>null</code>. 077 */ 078 public abstract Profiler addContext(String key, @Nullable Object value); 079 080}