-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…est context (#541)
- Loading branch information
Showing
21 changed files
with
348 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
cli/src/main/java/com/devonfw/tools/ide/log/IdeLoggerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.devonfw.tools.ide.log; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Implementation of {@link IdeLogger}. | ||
*/ | ||
public class IdeLoggerImpl implements IdeLogger { | ||
|
||
private final Function<IdeLogLevel, IdeSubLogger> loggerFactory; | ||
|
||
private final IdeSubLogger[] loggers; | ||
|
||
/** | ||
* @param minLogLevel the minimum enabled {@link IdeLogLevel}. | ||
* @param factory the factory to create active {@link IdeSubLogger} instances. | ||
*/ | ||
public IdeLoggerImpl(IdeLogLevel minLogLevel, Function<IdeLogLevel, IdeSubLogger> factory) { | ||
|
||
super(); | ||
this.loggerFactory = factory; | ||
this.loggers = new IdeSubLogger[IdeLogLevel.values().length]; | ||
setLogLevel(minLogLevel); | ||
} | ||
|
||
@Override | ||
public IdeSubLogger level(IdeLogLevel level) { | ||
|
||
IdeSubLogger logger = this.loggers[level.ordinal()]; | ||
Objects.requireNonNull(logger); | ||
return logger; | ||
} | ||
|
||
/** | ||
* Sets the log level. | ||
* | ||
* @param logLevel {@link IdeLogLevel} | ||
*/ | ||
public void setLogLevel(IdeLogLevel logLevel) { | ||
|
||
for (IdeLogLevel level : IdeLogLevel.values()) { | ||
boolean enabled = level.ordinal() >= logLevel.ordinal(); | ||
setLogLevel(level, enabled); | ||
} | ||
} | ||
|
||
/** | ||
* @param logLevel the {@link IdeLogLevel} to modify. | ||
* @param enabled - {@code true} to enable, {@code false} to disable. | ||
*/ | ||
public void setLogLevel(IdeLogLevel logLevel, boolean enabled) { | ||
|
||
IdeSubLogger logger; | ||
if (enabled) { | ||
logger = this.loggerFactory.apply(logLevel); | ||
} else { | ||
logger = IdeSubLoggerNone.of(logLevel); | ||
} | ||
this.loggers[logLevel.ordinal()] = logger; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.