Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
refactor(logger): rename ILogger.Priority to ILogger.Level
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Nov 7, 2023
1 parent 2e36388 commit efaeb04
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import com.itsaky.androidide.utils.ILogger
class IDELogFragment : LogViewFragment() {

private var logListener: ILogger.LogListener? =
ILogger.LogListener { priority, tag, message ->
ILogger.LogListener { level, tag, message ->
if (message.contains("\n")) {
val split = message.split("\n").toTypedArray()
for (line in split) {
logLine(priority, tag, line)
logLine(level, tag, line)
}
} else {
logLine(priority, tag, message)
logLine(level, tag, message)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import com.itsaky.androidide.editor.schemes.IDEColorSchemeProvider
import com.itsaky.androidide.fragments.EmptyStateFragment
import com.itsaky.androidide.models.LogLine
import com.itsaky.androidide.utils.ILogger
import com.itsaky.androidide.utils.ILogger.Priority
import com.itsaky.androidide.utils.ILogger.Level
import com.itsaky.androidide.utils.jetbrainsMono
import io.github.rosemoe.sora.widget.style.CursorAnimator
import java.util.concurrent.ArrayBlockingQueue
Expand Down Expand Up @@ -195,8 +195,8 @@ abstract class LogViewFragment :

abstract fun isSimpleFormattingEnabled(): Boolean

protected open fun logLine(priority: Priority, tag: String, message: String) {
val line = LogLine.obtain(priority, tag, message)
protected open fun logLine(level: Level, tag: String, message: String) {
val line = LogLine.obtain(level, tag, message)
appendLog(line)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient,

override fun logMessage(params: LogMessageParams) {
val line = params.toLogLine()
serverLogger.log(line.priority, line.formattedTagAndMessage())
serverLogger.log(line.level, line.formattedTagAndMessage())
}

override fun logOutput(line: String) {
Expand Down
2 changes: 1 addition & 1 deletion changelogs/v2.1.0-beta.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ AndroidIDE v2.0.0-beta is here with new features, improvements, bug fixes and a
- `Import orderer`: Organizes the imports. Thanks to @MrIkso (#180).
- XML Code formatter. Thanks to @MrIkso (#182).
- New Gradle command line options: `--build-cache` and `--offline`. Thanks to @MrIkso (#180).
- Highlight IDE logs based on the log line priority.
- Highlight IDE logs based on the log line level.
- Option to share Build Output, App log and IDE logs as text file.
- Syntax highlighting for Kotlin and C/C++ language. Thanks to @MrIkso (#196).
- Highlight hex color code in string literals. Thanks to @MrIkso (#209).
Expand Down
2 changes: 1 addition & 1 deletion changelogs/v2.1.2-beta.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Following issues have been fixed in this release :
- Hide tab layout when no files are opened (#330).
- Do not show full error message when layout inflation fails (#274).
- Use Storage Access Framework (SAF) for picking directories.
- 'Preview layout' item now has more priority than other options menu icons (#243).
- 'Preview layout' item now has more level than other options menu icons (#243).
- Do not show editor actions window when in search mode.
- Use relative padding in TreeView to support RTL layouts.
- Updated crash report. By @AndreyKozhev (#460).
Expand Down
2 changes: 1 addition & 1 deletion changelogs/v2.4.0-beta.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ _No notes_
## Improvements

- Improved colors in editor windows.
- Signture help window is now given more priority over the diagnostics window. This means, if the signature help window is visible to the user, the diagnostics window will not be shown.
- Signture help window is now given more level over the diagnostics window. This means, if the signature help window is visible to the user, the diagnostics window will not be shown.
- The IDE now releases some unnecessary resources when a file is deleted or renamed.
40 changes: 20 additions & 20 deletions editor/src/main/assets/editor/treesitter/log/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,87 @@
(time) @err.time
(pid) @err.pid
(tid) @err.tid
(priority) @err.priority
(level) @err.level
(tag) @err.tag
(message) @err.msg
(#match? @err.priority "E")
(#match? @err.level "E")
)

(log_line
(date) @warn.date
(time) @warn.time
(pid) @warn.pid
(tid) @warn.tid
(priority) @warn.priority
(level) @warn.level
(tag) @warn.tag
(message) @warn.msg
(#match? @warn.priority "W")
(#match? @warn.level "W")
)

(log_line
(date) @info.date
(time) @info.time
(pid) @info.pid
(tid) @info.tid
(priority) @info.priority
(level) @info.level
(tag) @info.tag
(message) @info.msg
(#match? @info.priority "I")
(#match? @info.level "I")
)

(log_line
(date) @debug.date
(time) @debug.time
(pid) @debug.pid
(tid) @debug.tid
(priority) @debug.priority
(level) @debug.level
(tag) @debug.tag
(message) @debug.msg
(#match? @debug.priority "D")
(#match? @debug.level "D")
)

(log_line
(date) @verbose.date
(time) @verbose.time
(pid) @verbose.pid
(tid) @verbose.tid
(priority) @verbose.priority
(level) @verbose.level
(tag) @verbose.tag
(message) @verbose.msg
(#match? @verbose.priority "V")
(#match? @verbose.level "V")
)

(ide_log_line
(ide_tag) @err.tag
(priority) @err.priority
(level) @err.level
(message) @err.msg
(#match? @err.priority "E")
(#match? @err.level "E")
)

(ide_log_line
(ide_tag) @warn.tag
(priority) @warn.priority
(level) @warn.level
(message) @warn.msg
(#match? @warn.priority "W")
(#match? @warn.level "W")
)

(ide_log_line
(ide_tag) @info.tag
(priority) @info.priority
(level) @info.level
(message) @info.msg
(#match? @info.priority "I")
(#match? @info.level "I")
)

(ide_log_line
(ide_tag) @debug.tag
(priority) @debug.priority
(level) @debug.level
(message) @debug.msg
(#match? @debug.priority "D")
(#match? @debug.level "D")
)

(ide_log_line
(ide_tag) @verbose.tag
(priority) @verbose.priority
(level) @verbose.level
(message) @verbose.msg
(#match? @verbose.priority "V")
(#match? @verbose.level "V")
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected AndroidLogger(String tag) {
}

@Override
protected void doLog(Priority priority, String message) {
switch (priority) {
protected void doLog(Level level, String message) {
switch (level) {
case ERROR:
Log.e(TAG, message);
break;
Expand Down
60 changes: 30 additions & 30 deletions logger/src/main/java/com/itsaky/androidide/utils/ILogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,45 +97,45 @@ public static ILogger newInstance(String tag) {
* @return This logger instance.
*/
public ILogger error(Object... messages) {
return log(Priority.ERROR, messages);
return log(Level.ERROR, messages);
}

/**
* Log messages with the given priority.
* Log messages with the given log level.
*
* @param priority The priority of the log messages.
* @param level The log level of the messages.
* @param messages The messages to log.
* @return This logger instance.
*/
public ILogger log(Priority priority, Object... messages) {
logAndNotify(priority, generateMessage(messages));
public ILogger log(Level level, Object... messages) {
logAndNotify(level, generateMessage(messages));
return this;
}

private void logAndNotify(Priority priority, String msg) {
private void logAndNotify(Level level, String msg) {
if (!isEnabled()) {
// logger is disabled
return;
}

doLog(priority, msg);
doLog(level, msg);
for (final var listener : logListeners) {
listener.log(priority, TAG, msg);
listener.log(level, TAG, msg);
}
}

/**
* Log the message to an appropriate stream where the user can see the log messages.
*
* @param priority The priority for this log message.
* @param message The full generated message for this log. Might contain new lines.
* @see ILogger.Priority#DEBUG
* @see ILogger.Priority#ERROR
* @see ILogger.Priority#WARNING
* @see ILogger.Priority#VERBOSE
* @see ILogger.Priority#INFO
* @param level The log level for this message.
* @param message The full generated message for this log. Might contain new lines.
* @see Level#DEBUG
* @see Level#ERROR
* @see Level#WARNING
* @see Level#VERBOSE
* @see Level#INFO
*/
protected abstract void doLog(Priority priority, String message);
protected abstract void doLog(Level level, String message);

protected String generateMessage(Object... messages) {
StringBuilder sb = new StringBuilder();
Expand All @@ -159,7 +159,7 @@ protected String generateMessage(Object... messages) {
* @return This logger instance.
*/
public ILogger warn(Object... messages) {
return log(Priority.WARNING, messages);
return log(Level.WARNING, messages);
}

/**
Expand All @@ -169,7 +169,7 @@ public ILogger warn(Object... messages) {
* @return This logger instance.
*/
public ILogger verbose(Object... messages) {
return log(Priority.VERBOSE, messages);
return log(Level.VERBOSE, messages);
}

/**
Expand All @@ -179,7 +179,7 @@ public ILogger verbose(Object... messages) {
* @return This logger instance.
*/
public ILogger info(Object... messages) {
return log(Priority.INFO, messages);
return log(Level.INFO, messages);
}

/**
Expand All @@ -196,7 +196,7 @@ public void logThis() {
* @return This logger instance.
*/
public ILogger debug(Object... messages) {
return log(Priority.DEBUG, messages);
return log(Level.DEBUG, messages);
}

/**
Expand Down Expand Up @@ -234,31 +234,31 @@ protected String getCallerClassDescription() {
}

/**
* Logging priority.
* Logging level.
*/
public enum Priority {
public enum Level {

DEBUG('D'),
WARNING('W'),
ERROR('E'),
INFO('I'),
VERBOSE('V');

public final char priorityChar;
public final char levelChar;

Priority(char priorityChar) {
this.priorityChar = priorityChar;
Level(char levelChar) {
this.levelChar = levelChar;
}

public static Priority forChar(char c) {
public static Level forChar(char c) {
c = Character.toUpperCase(c);
for (Priority value : values()) {
if (value.priorityChar == c) {
for (Level value : values()) {
if (value.levelChar == c) {
return value;
}
}

throw new IllegalArgumentException("Invalid priority char " + c);
throw new IllegalArgumentException("Invalid level char " + c);
}
}

Expand All @@ -267,6 +267,6 @@ public static Priority forChar(char c) {
*/
public interface LogListener {

void log(Priority priority, String tag, String message);
void log(Level level, String tag, String message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ protected JvmLogger(String tag) {
}

@Override
protected void doLog(Priority priority, String message) {
protected void doLog(Level level, String message) {
if (interceptor != null) {
interceptor.onLog(priority, TAG, message);
interceptor.onLog(level, TAG, message);
} else {
System.err.printf(
"%-25s %-2s %s%n",
trimTagIfNeeded(TAG, 25),
priority.priorityChar,
level.levelChar,
message
);
}
}

public interface LogInterceptor {

void onLog(Priority priority, String tag, String message);
void onLog(Level level, String tag, String message);
}
}
8 changes: 4 additions & 4 deletions resources/src/main/res/raw/attrs_xml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5445,8 +5445,8 @@
<p>Only a single non-rectangular clip can be applied on a View at any time. Circular
clips from a
{@link android.view.ViewAnimationUtils#createCircularReveal(View, int, int, float,
float)} circular reveal animation take priority over Outline clipping, and child
Outline clipping takes priority over Outline clipping done by a parent.
float)} circular reveal animation take level over Outline clipping, and child
Outline clipping takes level over Outline clipping done by a parent.
<p>Note that this flag will only be respected if the View's Outline returns true from
{@link android.graphics.Outline#canClip()}. -->
<attr
Expand Down Expand Up @@ -10650,8 +10650,8 @@
name="bottom_to_top"
value="0x2" />
</attr>
<!-- Priority of the rows and columns. When the priority is none,
both rows and columns have the same priority. When the priority is
<!-- Priority of the rows and columns. When the level is none,
both rows and columns have the same level. When the level is
column, the animations will be applied on the columns first. The same
goes for rows. -->
<attr name="directionPriority">
Expand Down
Loading

0 comments on commit efaeb04

Please sign in to comment.