Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 75dbc4f

Browse files
committed
Merge pull request #1784 from dodgex/1721_cut_log_tags_to_23_chars
Cut log tags to 23 chars
2 parents d0e99f8 + f5d5eb1 commit 75dbc4f

5 files changed

Lines changed: 64 additions & 8 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.helper;
17+
18+
import org.androidannotations.holder.GeneratedClassHolder;
19+
20+
public final class LogHelper {
21+
22+
private static final int MAX_TAG_LEN = 23;
23+
24+
private LogHelper() {
25+
}
26+
27+
/**
28+
* Log tag length needs to be limited to 23.
29+
*
30+
* @see <a href=
31+
* "http://developer.android.com/reference/android/util/Log.html#isLoggable(java.lang.String,%20int)">
32+
* Log.isLoggable() JavaDoc</a>
33+
*/
34+
public static String trimLogTag(String tag) {
35+
if (tag == null) {
36+
return "";
37+
} else if (tag.length() > MAX_TAG_LEN) {
38+
return tag.substring(0, MAX_TAG_LEN);
39+
} else {
40+
return tag;
41+
}
42+
}
43+
44+
/**
45+
* Log tag length needs to be limited to 23.
46+
*
47+
* @see <a href=
48+
* "http://developer.android.com/reference/android/util/Log.html#isLoggable(java.lang.String,%20int)">
49+
* Log.isLoggable() JavaDoc</a>
50+
*/
51+
public static String logTagForClassHolder(GeneratedClassHolder holder) {
52+
return trimLogTag(holder.getGeneratedClass().name());
53+
}
54+
}

‎AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/RootContextHandler.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static com.helger.jcodemodel.JExpr.cast;
1919
import static com.helger.jcodemodel.JExpr.lit;
20+
import static org.androidannotations.helper.LogHelper.logTagForClassHolder;
2021

2122
import javax.lang.model.element.Element;
2223
import javax.lang.model.type.TypeMirror;
@@ -82,7 +83,7 @@ public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EBeanHo
8283
cond._then().add(fieldRef.assign(cast(extendingContextClass, holder.getContextRef())));
8384

8485
JInvocation warningInvoke = getClasses().LOG.staticInvoke("w");
85-
warningInvoke.arg(holder.getGeneratedClass().name());
86+
warningInvoke.arg(logTagForClassHolder(holder));
8687
warningInvoke.arg(lit("Due to Context class ").plus(holder.getContextRef().invoke("getClass").invoke("getSimpleName"))
8788
.plus(lit(", the @RootContext " + extendingContextClass.name() + " won't be populated")));
8889
cond._else().add(warningInvoke);

‎AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/TraceHandler.java‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.androidannotations.helper.AndroidConstants.LOG_INFO;
2121
import static org.androidannotations.helper.AndroidConstants.LOG_VERBOSE;
2222
import static org.androidannotations.helper.AndroidConstants.LOG_WARN;
23+
import static org.androidannotations.helper.LogHelper.trimLogTag;
2324

2425
import java.util.ArrayList;
2526
import java.util.Arrays;
@@ -83,7 +84,7 @@ public void process(Element element, EComponentHolder holder) throws Exception {
8384
JBlock methodBody = method.body();
8485

8586
JInvocation isLoggableInvocation = getClasses().LOG.staticInvoke("isLoggable");
86-
isLoggableInvocation.arg(JExpr.lit(tag)).arg(logLevelFromInt(level, getClasses().LOG));
87+
isLoggableInvocation.arg(tag).arg(logLevelFromInt(level, getClasses().LOG));
8788

8889
JConditional ifStatement = methodBody._if(isLoggableInvocation);
8990

@@ -243,9 +244,6 @@ private String extractTag(Element element) {
243244
if (Trace.DEFAULT_TAG.equals(tag)) {
244245
tag = element.getEnclosingElement().getSimpleName().toString();
245246
}
246-
if (tag.length() > 23) {
247-
tag = tag.substring(0, 23);
248-
}
249-
return tag;
247+
return trimLogTag(tag);
250248
}
251249
}

‎AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/core/handler/TransactionalHandler.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.androidannotations.internal.core.handler;
1717

18+
import static org.androidannotations.helper.LogHelper.logTagForClassHolder;
19+
1820
import javax.lang.model.element.Element;
1921
import javax.lang.model.element.ExecutableElement;
2022

@@ -102,7 +104,7 @@ public void process(Element element, EComponentHolder holder) {
102104

103105
JInvocation errorInvoke = catchBody.staticInvoke(getClasses().LOG, "e");
104106

105-
errorInvoke.arg(holder.getGeneratedClass().name());
107+
errorInvoke.arg(logTagForClassHolder(holder));
106108
errorInvoke.arg("Error in transaction");
107109
errorInvoke.arg(exceptionParam);
108110

‎AndroidAnnotations/androidannotations-ormlite/ormlite/src/main/java/org/androidannotations/ormlite/handler/OrmLiteDaoHandler.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static com.helger.jcodemodel.JExpr._new;
1919
import static com.helger.jcodemodel.JExpr.cast;
20+
import static org.androidannotations.helper.LogHelper.logTagForClassHolder;
2021

2122
import javax.lang.model.element.Element;
2223
import javax.lang.model.type.TypeMirror;
@@ -108,7 +109,7 @@ public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, ECompon
108109
String fieldName = param.getSimpleName().toString();
109110
catchBlock.body() //
110111
.staticInvoke(getClasses().LOG, "e") //
111-
.arg(holder.getGeneratedClass().name()) //
112+
.arg(logTagForClassHolder(holder))//
112113
.arg("Could not create DAO " + fieldName) //
113114
.arg(exception);
114115
}

0 commit comments

Comments
 (0)