View Javadoc
1   /*
2    * Copyright 2018 SPF4J.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.spf4j.test.log;
17  
18  import javax.annotation.Nullable;
19  import javax.annotation.ParametersAreNonnullByDefault;
20  import javax.annotation.concurrent.ThreadSafe;
21  import org.spf4j.log.Level;
22  
23  /**
24   * @author Zoltan Farkas
25   */
26  @ParametersAreNonnullByDefault
27  @ThreadSafe
28  public interface LogHandler  {
29  
30    enum Handling {
31      /* Will handle this message, and potentially pass it downstream */
32      HANDLE_PASS,
33      /** Will handle this message, and will consume it. */
34      HANDLE_CONSUME,
35      /** Not handling these messages */
36      NONE
37    }
38  
39    /**
40     * find out if this handler should be used for the given log level.
41     * @param level the log level.
42     * @return Handling enum that, specifies what this handler does with these messages.
43     */
44    Handling handles(Level level);
45  
46    /**
47     * Handler handling method
48     * @param record the log record.
49     * @return return the log message potentially with an attachment,
50     * or null if the handler does not want to pass the message downstream.
51     */
52    @Nullable
53    TestLogRecord handle(TestLogRecord record);
54  
55  }