This commit is contained in:
Igor I
2025-08-25 09:04:23 +05:00
parent 9d750fc6a3
commit 930ae8eafb
5 changed files with 74 additions and 3 deletions

View File

@ -0,0 +1,16 @@
package logging;
import android.util.Log;
public class AndroidLogger implements Logger {
private final String tag;
public AndroidLogger(Class<?> clazz) {
this.tag = clazz.getSimpleName();
}
public void debug(String msg) { Log.d(tag, msg); }
public void info(String msg) { Log.i(tag, msg); }
public void warn(String msg) { Log.w(tag, msg); }
public void error(String msg) { Log.e(tag, msg); }
}

View File

@ -0,0 +1,12 @@
package logging;
public interface Logger {
void debug(String msg);
void info(String msg);
void warn(String msg);
void error(String msg);
static Logger getLogger(Class<?> clazz) {
return LoggerFactory.createLogger(clazz); // Подменяется реализацией
}
}

View File

@ -0,0 +1,21 @@
package logging;
public class LoggerFactory {
public static Logger createLogger(Class<?> clazz) {
// Тут выбираешь реализацию по флагу/условию
//if (isAndroid()) {
return new AndroidLogger(clazz);
//} else {
// return new SLF4JLogger(clazz);
//}
}
private static boolean isAndroid() {
try {
Class.forName("android.os.Build");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}