|
1 | 1 | package io.github.intisy.gradle.github; |
2 | 2 |
|
3 | 3 | import org.gradle.api.Project; |
| 4 | +import org.gradle.api.logging.LogLevel; |
4 | 5 |
|
5 | 6 | public class Logger { |
6 | 7 | private final GithubExtension extension; |
7 | 8 | private final Project project; |
| 9 | + /** |
| 10 | + * Constructs a new instance of Logger using the provided {@link Project} instance. |
| 11 | + * |
| 12 | + * @param project The {@link Project} instance associated with this Logger. |
| 13 | + * |
| 14 | + * @throws NullPointerException If the {@code project} is null. |
| 15 | + * |
| 16 | + * @see GithubExtension |
| 17 | + */ |
8 | 18 | public Logger(Project project) { |
| 19 | + this(project.getExtensions().getByType(GithubExtension.class), project); |
| 20 | + } |
| 21 | + /** |
| 22 | + * Constructs a new instance of Logger. |
| 23 | + * |
| 24 | + * @param extension The {@link GithubExtension} instance to be used for logging configuration. |
| 25 | + * @param project The {@link Project} instance associated with this Logger. |
| 26 | + * |
| 27 | + * @throws NullPointerException If either {@code extension} or {@code project} is null. |
| 28 | + */ |
| 29 | + public Logger(GithubExtension extension, Project project) { |
| 30 | + if (extension == null || project == null) { |
| 31 | + throw new NullPointerException("extension and project cannot be null"); |
| 32 | + } |
| 33 | + this.extension = extension; |
9 | 34 | this.project = project; |
10 | | - this.extension = project.getExtensions().getByType(GithubExtension.class); |
11 | 35 | } |
| 36 | + /** |
| 37 | + * Logs a message at the lifecycle level. |
| 38 | + * |
| 39 | + * @param message The message to be logged. |
| 40 | + */ |
12 | 41 | public void log(String message) { |
13 | 42 | project.getLogger().lifecycle(message); |
14 | 43 | } |
15 | 44 |
|
| 45 | + /** |
| 46 | + * Logs an error message. |
| 47 | + * |
| 48 | + * @param message The error message to be logged. |
| 49 | + */ |
16 | 50 | public void error(String message) { |
17 | 51 | project.getLogger().error(message); |
18 | 52 | } |
19 | 53 |
|
| 54 | + /** |
| 55 | + * Logs a debug message if the debug mode is enabled or the log level is INFO or DEBUG. |
| 56 | + * |
| 57 | + * @param message The debug message to be logged. |
| 58 | + */ |
20 | 59 | public void debug(String message) { |
21 | | - if (extension.isDebug()) { |
| 60 | + LogLevel logLevel = project.getGradle().getStartParameter().getLogLevel(); |
| 61 | + if (extension.isDebug() || logLevel.equals(LogLevel.INFO) || logLevel.equals(LogLevel.DEBUG)) { |
22 | 62 | project.getLogger().lifecycle(message); |
23 | 63 | } |
24 | 64 | } |
25 | 65 |
|
| 66 | + /** |
| 67 | + * Logs a warning message. |
| 68 | + * |
| 69 | + * @param message The warning message to be logged. |
| 70 | + */ |
26 | 71 | public void warn(String message) { |
27 | 72 | project.getLogger().warn(message); |
28 | 73 | } |
|
0 commit comments