View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.api.cli;
20  
21  import org.apache.maven.api.annotations.Experimental;
22  import org.apache.maven.api.annotations.Nonnull;
23  import org.apache.maven.api.annotations.Nullable;
24  
25  /**
26   * Defines a simple logging interface for Maven CLI operations.
27   * This interface provides methods for logging messages at different severity levels
28   * and supports logging with or without associated exceptions.
29   *
30   * @since 4.0.0
31   */
32  @Experimental
33  public interface Logger {
34  
35      /**
36       * Represents the severity levels for log messages.
37       */
38      enum Level {
39          DEBUG,
40          INFO,
41          WARN,
42          ERROR
43      }
44  
45      /**
46       * Logs a message at the specified level without an associated exception.
47       *
48       * @param level the severity level of the message
49       * @param message the message to be logged
50       */
51      default void log(@Nonnull Level level, @Nonnull String message) {
52          log(level, message, null);
53      }
54  
55      /**
56       * Logs a message at the specified level with an associated exception.
57       *
58       * @param level the severity level of the message
59       * @param message the message to be logged
60       * @param error the associated exception, or null if not applicable
61       */
62      void log(@Nonnull Level level, @Nonnull String message, @Nullable Throwable error);
63  
64      /**
65       * Logs a debug message without an associated exception.
66       *
67       * @param message the debug message to be logged
68       */
69      default void debug(String message) {
70          log(Level.DEBUG, message);
71      }
72  
73      /**
74       * Logs a debug message with an associated exception.
75       *
76       * @param message the debug message to be logged
77       * @param error the associated exception
78       */
79      default void debug(@Nonnull String message, @Nullable Throwable error) {
80          log(Level.DEBUG, message, error);
81      }
82  
83      /**
84       * Logs an info message without an associated exception.
85       *
86       * @param message the info message to be logged
87       */
88      default void info(@Nonnull String message) {
89          log(Level.INFO, message);
90      }
91  
92      /**
93       * Logs an info message with an associated exception.
94       *
95       * @param message the info message to be logged
96       * @param error the associated exception
97       */
98      default void info(@Nonnull String message, @Nullable Throwable error) {
99          log(Level.INFO, message, error);
100     }
101 
102     /**
103      * Logs a warning message without an associated exception.
104      *
105      * @param message the warning message to be logged
106      */
107     default void warn(@Nonnull String message) {
108         log(Level.WARN, message);
109     }
110 
111     /**
112      * Logs a warning message with an associated exception.
113      *
114      * @param message the warning message to be logged
115      * @param error the associated exception
116      */
117     default void warn(@Nonnull String message, @Nullable Throwable error) {
118         log(Level.WARN, message, error);
119     }
120 
121     /**
122      * Logs an error message without an associated exception.
123      *
124      * @param message the error message to be logged
125      */
126     default void error(@Nonnull String message) {
127         log(Level.ERROR, message);
128     }
129 
130     /**
131      * Logs an error message with an associated exception.
132      *
133      * @param message the error message to be logged
134      * @param error the associated exception
135      */
136     default void error(@Nonnull String message, @Nullable Throwable error) {
137         log(Level.ERROR, message, error);
138     }
139 }