001/*
002 * SonarQube
003 * Copyright (C) 2009-2017 SonarSource SA
004 * mailto:info AT sonarsource DOT com
005 *
006 * This program 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 * This program 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 stopInfo(boolean cacheUsed);
070
071  public abstract Profiler stopTrace(String message);
072
073  public abstract Profiler stopDebug(String message);
074
075  public abstract Profiler stopInfo(String message);
076
077  /**
078   * Context information is removed if value is <code>null</code>.
079   */
080  public abstract Profiler addContext(String key, @Nullable Object value);
081
082}