Update 1
This commit is contained in:
parent
63290cd3a2
commit
52a93601dd
18
build.gradle
18
build.gradle
@ -3,8 +3,8 @@ plugins {
|
|||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'org.example'
|
group 'fr.doap.llog'
|
||||||
version '1.0-SNAPSHOT'
|
version '0.1'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@ -32,16 +32,20 @@ def getDate() {
|
|||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
mavenJava(MavenPublication) {
|
mavenJava(MavenPublication) {
|
||||||
groupId = 'fr.doap.dlog'
|
groupId = "${group}"
|
||||||
artifactId = 'dlog'
|
artifactId = "llog"
|
||||||
version = "0.9.4-SNAPSHOT"
|
version = "${version}"
|
||||||
from components.java
|
from components.java
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
// url = "https://maven.doap.fr/repository/maven-releases/"
|
if (project.version.endsWith('-SNAPSHOT')) {
|
||||||
url = "https://maven.doap.fr/repository/maven-snapshots/"
|
url "https://maven.doap.fr/repository/maven-snapshots/"
|
||||||
|
} else {
|
||||||
|
url "https://maven.doap.fr/repository/maven-releases/"
|
||||||
|
}
|
||||||
|
|
||||||
credentials {
|
credentials {
|
||||||
username privateProperties["mavenUsername"]
|
username privateProperties["mavenUsername"]
|
||||||
password privateProperties["mavenPassword"]
|
password privateProperties["mavenPassword"]
|
||||||
|
55
src/main/java/fr/doap/llog/Dict.java
Normal file
55
src/main/java/fr/doap/llog/Dict.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package fr.doap.llog;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Dict<T> {
|
||||||
|
|
||||||
|
public void put(String aKey, T aValue) {
|
||||||
|
if (aKey == null || aKey.length() == 0) mValue = aValue;
|
||||||
|
else {
|
||||||
|
String[] lS = aKey.split("[.]", 2);
|
||||||
|
Dict<T> lD = mDict.get(lS[0]);
|
||||||
|
if (lD == null) {
|
||||||
|
lD = new Dict<>();
|
||||||
|
mDict.put(lS[0], lD);
|
||||||
|
}
|
||||||
|
if (lS.length > 1) lD.put(lS[1], aValue);
|
||||||
|
else lD.put("", aValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(String aKey) {
|
||||||
|
if (aKey == null || aKey.length() == 0) return mValue;
|
||||||
|
else {
|
||||||
|
String[] lS = aKey.split("[.]", 2);
|
||||||
|
Dict<T> lD = mDict.get(lS[0]);
|
||||||
|
if (lD == null) return mValue;
|
||||||
|
else {
|
||||||
|
T lT = lD.mValue;
|
||||||
|
if (lS.length > 1) lT = lD.get(lS[1]);
|
||||||
|
if (lT == null) return mValue;
|
||||||
|
else return lT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "\n{\n"+toString(0)+"}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String toString(int aI) {
|
||||||
|
String lR = ": "+ mValue+"\n";
|
||||||
|
for (Map.Entry<String, Dict<T>> me: mDict.entrySet()) lR += spc(aI+1)+me.getKey()+me.getValue().toString(aI+1);
|
||||||
|
return lR;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String spc(int aI) {
|
||||||
|
String l = "";
|
||||||
|
for (int i=0; i<aI; i++) l += " ";
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Dict<T>> mDict = new HashMap<>();
|
||||||
|
private T mValue;
|
||||||
|
}
|
6
src/main/java/fr/doap/llog/Filter.java
Normal file
6
src/main/java/fr/doap/llog/Filter.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package fr.doap.llog;
|
||||||
|
|
||||||
|
public class Filter {
|
||||||
|
public int mLogLevel;
|
||||||
|
public int mSTLevel;
|
||||||
|
}
|
@ -11,8 +11,10 @@ public class L {
|
|||||||
mL.mLooper.post(lLogMsg);
|
mL.mLooper.post(lLogMsg);
|
||||||
return lLogMsg;
|
return lLogMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public void filter(String aKey, Filter aFilter) {
|
||||||
|
mL.mLooper.put(aKey,aFilter);
|
||||||
|
}
|
||||||
|
|
||||||
private LogLooper mLooper = new LogLooper();
|
private LogLooper mLooper = new LogLooper();
|
||||||
|
|
||||||
private ILogger mLogger;
|
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,52 @@
|
|||||||
package fr.doap.llog;
|
package fr.doap.llog;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class LogLooper extends ThreadLooper {
|
public class LogLooper extends ThreadLooper {
|
||||||
|
|
||||||
public void post(LogMsg aLogMsg) {
|
public void post(LogMsg aLogMsg) {
|
||||||
add(new LLMsg(aLogMsg));
|
add(new LLMsg(aLogMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void put(String aKey, Filter aF) {
|
||||||
|
mFilters.put(aKey, aF);
|
||||||
|
}
|
||||||
|
|
||||||
public class LLMsg implements WorkItem {
|
public class LLMsg implements WorkItem {
|
||||||
public LLMsg(LogMsg aLogMsg) { mLogMsg = aLogMsg; }
|
public LLMsg(LogMsg aLogMsg) { mLogMsg = aLogMsg; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
int lI = mLogMsg.getCallerIndex();
|
||||||
|
StackTraceElement lS = mLogMsg.mSTE[lI];
|
||||||
|
String lClass = lS.getClassName();
|
||||||
|
lClass = lClass.substring(lClass.lastIndexOf('.'));
|
||||||
|
if (mLogMsg.mTag == null || mLogMsg.mTag.isEmpty()) mLogMsg.mTag = lClass;
|
||||||
|
String lC = lS.getClassName() + "." + lS.getMethodName();
|
||||||
|
Filter lF = mFilters.get(lC);
|
||||||
|
if (lF != null) {
|
||||||
|
if (mLogMsg.mSeverity >= lF.mLogLevel) {
|
||||||
|
System.out.println(mLogMsg.mSeverity+ "-" + lC + ": " + mLogMsg.mMessage + " (" + lS.getFileName() + ":" + lS.getLineNumber() + ")");
|
||||||
|
if (mLogMsg.mSeverity <= lF.mSTLevel) {
|
||||||
|
for (int i=lI+1; i<mLogMsg.mSTE.length; i++) {
|
||||||
|
StackTraceElement l = mLogMsg.mSTE[i];
|
||||||
|
System.out.println(" "+l.getClassName() + "." + l.getMethodName() + " (" + l.getFileName() + ":" + l.getLineNumber() + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println(lS.getClassName() + "." + lS.getMethodName() + ": " + mLogMsg.mMessage + " (" + lS.getFileName() + ":" + lS.getLineNumber() + ")");
|
||||||
|
}
|
||||||
|
/*
|
||||||
for (int i=mLogMsg.getCallerIndex(); i<mLogMsg.mSTE.length; i++) {
|
for (int i=mLogMsg.getCallerIndex(); i<mLogMsg.mSTE.length; i++) {
|
||||||
StackTraceElement lS = mLogMsg.mSTE[i];
|
StackTraceElement lS = mLogMsg.mSTE[i];
|
||||||
System.out.println(lS.getClassName() + "." + lS.getMethodName() + ": " + mLogMsg.mMessage + " (" + lS.getFileName() + ":" + lS.getLineNumber() + ")");
|
System.out.println(lS.getClassName() + "." + lS.getMethodName() + ": " + mLogMsg.mMessage + " (" + lS.getFileName() + ":" + lS.getLineNumber() + ")");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private LogMsg mLogMsg;
|
private LogMsg mLogMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Dict<Filter> mFilters = new Dict<>();
|
||||||
}
|
}
|
||||||
|
@ -59,8 +59,8 @@ public class ThreadLooper {
|
|||||||
onStartWaiting();
|
onStartWaiting();
|
||||||
ThreadLooper.this.wait();
|
ThreadLooper.this.wait();
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
System.out.println("Interrupted");
|
// System.out.println("Interrupted");
|
||||||
System.out.println("Caller threads: "+ mCallerThreads);
|
// System.out.println("Caller threads: "+ mCallerThreads);
|
||||||
if (mCallerThreads.isEmpty()) Thread.currentThread().interrupt();
|
if (mCallerThreads.isEmpty()) Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,54 @@
|
|||||||
package fr.doap.test;
|
package fr.doap.test;
|
||||||
|
|
||||||
import fr.doap.llog.L;
|
import fr.doap.llog.*;
|
||||||
|
|
||||||
public class Test {
|
public class Test {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
L.l(1, null, "test", "Message sans format");
|
L.l(1, null, "test", "Message sans format");
|
||||||
test1();
|
test1();
|
||||||
|
testDict();
|
||||||
|
testFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void test1() {
|
protected static void test1() {
|
||||||
L.l(1, null, "test", "Message avec format: %s", "toto");
|
L.l(1, null, "test", "Message avec format: %s", "toto");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static void testDict() {
|
||||||
|
Dict<String> lD = new Dict<>();
|
||||||
|
L.l(1, null, "Dict", "Empty: %s", lD.toString());
|
||||||
|
lD.put("fr.doap", "fr_doap");
|
||||||
|
L.l(1, null, "Dict", "1: %s", lD.toString());
|
||||||
|
lD.put("com.doap.fr", "com_doap_fr");
|
||||||
|
L.l(1, null, "Dict", "2: %s", lD.toString());
|
||||||
|
lD.put("com", "com");
|
||||||
|
L.l(1, null, "Dict", "3: %s", lD.toString());
|
||||||
|
lD.put("fr.doap.llog", "fr_doap_llog");
|
||||||
|
L.l(1, null, "Dict", "4: %s", lD.toString());
|
||||||
|
lD.put("", "ROOT");
|
||||||
|
L.l(1, null, "Dict", "5: %s", lD.toString());
|
||||||
|
lD.put("com.doap.fr", "com_doap_fr+++");
|
||||||
|
L.l(1, null, "Dict", "6: %s", lD.toString());
|
||||||
|
L.l(1, null, "Dict", "fr.doap.llog: %s", lD.get("fr.doap.llog"));
|
||||||
|
L.l(1, null, "Dict", "fr: %s", lD.get("fr"));
|
||||||
|
L.l(1, null, "Dict", "com.doap.fr.toto: %s", lD.get("com.doap.fr.toto"));
|
||||||
|
L.l(1, null, "Dict", "com.bibi: %s", lD.get("com.bibi"));
|
||||||
|
L.l(1, null, "Dict", "org.tata: %s", lD.get("org.tata"));
|
||||||
|
L.l(1, null, "Dict", "com.doap: %s", lD.get("com.doap"));
|
||||||
|
L.l(1, null, "Dict", "com.doap.bibi: %s", lD.get("com.doap.bibi"));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void testFilter() {
|
||||||
|
Filter lF = new Filter();
|
||||||
|
lF.mLogLevel = 3;
|
||||||
|
lF.mSTLevel = 5;
|
||||||
|
L.filter("", lF);
|
||||||
|
L.l(10, null, "Dict", "Always show");
|
||||||
|
L.l(6, null, "Dict", "Always show 6");
|
||||||
|
L.l(5, null, "Dict", "Always with ST 5");
|
||||||
|
L.l(3, null, "Dict", "Always with ST 3");
|
||||||
|
L.l(2, null, "Dict", "Never show");
|
||||||
|
L.l(100, null, "Dict", "Finished");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user