Skip to content

Commit cc2cfc7

Browse files
committed
Add logs
1 parent 2073ef0 commit cc2cfc7

8 files changed

Lines changed: 414 additions & 102 deletions

File tree

Lines changed: 102 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,110 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
45

5-
<parent>
6-
<groupId>org.androidannotations</groupId>
7-
<artifactId>androidannotations-parent</artifactId>
8-
<version>3.0-SNAPSHOT</version>
9-
</parent>
6+
<parent>
7+
<groupId>org.androidannotations</groupId>
8+
<artifactId>androidannotations-parent</artifactId>
9+
<version>3.0-SNAPSHOT</version>
10+
</parent>
1011

11-
<artifactId>androidannotations</artifactId>
12-
<name>AndroidAnnotations Annotation Processor</name>
13-
<description>The Annotation Processor jar that generates code</description>
12+
<artifactId>androidannotations</artifactId>
13+
<name>AndroidAnnotations Annotation Processor</name>
14+
<description>The Annotation Processor jar that generates code</description>
1415

15-
<dependencies>
16-
<dependency>
17-
<groupId>org.androidannotations</groupId>
18-
<artifactId>androidannotations-api</artifactId>
19-
</dependency>
20-
<dependency>
21-
<groupId>com.sun.codemodel</groupId>
22-
<artifactId>codemodel</artifactId>
23-
</dependency>
24-
<dependency>
25-
<groupId>junit</groupId>
26-
<artifactId>junit</artifactId>
27-
</dependency>
28-
<dependency>
29-
<groupId>com.google.guava</groupId>
30-
<artifactId>guava</artifactId>
31-
</dependency>
32-
<dependency>
33-
<groupId>com.google.android</groupId>
34-
<artifactId>android</artifactId>
35-
<version>1.6_r2</version>
36-
<scope>provided</scope>
37-
</dependency>
38-
<dependency>
39-
<!-- spring-android-rest-template is required to use the Rest API -->
40-
<groupId>org.springframework.android</groupId>
41-
<artifactId>spring-android-rest-template</artifactId>
42-
<version>1.0.0.RELEASE</version>
43-
<scope>test</scope>
44-
</dependency>
45-
</dependencies>
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.androidannotations</groupId>
19+
<artifactId>androidannotations-api</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>com.sun.codemodel</groupId>
23+
<artifactId>codemodel</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>junit</groupId>
27+
<artifactId>junit</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>com.google.guava</groupId>
31+
<artifactId>guava</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.google.android</groupId>
35+
<artifactId>android</artifactId>
36+
<version>1.6_r2</version>
37+
<scope>provided</scope>
38+
</dependency>
39+
<dependency>
40+
<!-- spring-android-rest-template is required to use the Rest API -->
41+
<groupId>org.springframework.android</groupId>
42+
<artifactId>spring-android-rest-template</artifactId>
43+
<version>1.0.0.RELEASE</version>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
4647

47-
<build>
48-
<plugins>
49-
<plugin>
50-
<groupId>org.apache.maven.plugins</groupId>
51-
<artifactId>maven-compiler-plugin</artifactId>
52-
<configuration>
53-
<source>1.6</source>
54-
<target>1.6</target>
55-
<compilerArgument>-proc:none</compilerArgument>
56-
</configuration>
57-
</plugin>
58-
<plugin>
59-
<artifactId>maven-javadoc-plugin</artifactId>
60-
<executions>
61-
<execution>
62-
<id>attach-javadocs</id>
63-
<goals>
64-
<goal>jar</goal>
65-
</goals>
66-
</execution>
67-
</executions>
68-
</plugin>
69-
<plugin>
70-
<artifactId>maven-source-plugin</artifactId>
71-
<executions>
72-
<execution>
73-
<id>attach-sources</id>
74-
<goals>
75-
<goal>jar</goal>
76-
</goals>
77-
</execution>
78-
</executions>
79-
</plugin>
80-
<plugin>
81-
<groupId>org.apache.maven.plugins</groupId>
82-
<artifactId>maven-resources-plugin</artifactId>
83-
</plugin>
84-
</plugins>
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.apache.maven.plugins</groupId>
52+
<artifactId>maven-compiler-plugin</artifactId>
53+
<configuration>
54+
<source>1.6</source>
55+
<target>1.6</target>
56+
<compilerArgument>-proc:none</compilerArgument>
57+
</configuration>
58+
</plugin>
59+
<plugin>
60+
<artifactId>maven-javadoc-plugin</artifactId>
61+
<executions>
62+
<execution>
63+
<id>attach-javadocs</id>
64+
<goals>
65+
<goal>jar</goal>
66+
</goals>
67+
</execution>
68+
</executions>
69+
</plugin>
70+
<plugin>
71+
<artifactId>maven-source-plugin</artifactId>
72+
<executions>
73+
<execution>
74+
<id>attach-sources</id>
75+
<goals>
76+
<goal>jar</goal>
77+
</goals>
78+
</execution>
79+
</executions>
80+
</plugin>
81+
<plugin>
82+
<groupId>org.apache.maven.plugins</groupId>
83+
<artifactId>maven-resources-plugin</artifactId>
84+
</plugin>
85+
</plugins>
8586

86-
<resources>
87-
<resource>
88-
<directory>src/main/resources</directory>
89-
<excludes>
90-
<exclude>rebel.xml</exclude>
91-
</excludes>
92-
</resource>
93-
<resource>
94-
<directory>src/main/java</directory>
95-
<includes>
96-
<include>org/androidannotations/api/**</include>
97-
</includes>
98-
</resource>
99-
<resource>
100-
<directory>src/main/resources</directory>
101-
<filtering>true</filtering>
102-
<includes>
103-
<include>**/*.properties</include>
104-
</includes>
105-
</resource>
106-
</resources>
107-
</build>
87+
<resources>
88+
<resource>
89+
<directory>src/main/resources</directory>
90+
<excludes>
91+
<exclude>rebel.xml</exclude>
92+
</excludes>
93+
</resource>
94+
<resource>
95+
<directory>src/main/java</directory>
96+
<includes>
97+
<include>org/androidannotations/api/**</include>
98+
</includes>
99+
</resource>
100+
<resource>
101+
<directory>src/main/resources</directory>
102+
<filtering>true</filtering>
103+
<includes>
104+
<include>**/*.properties</include>
105+
</includes>
106+
</resource>
107+
</resources>
108+
</build>
108109

109110
</project>

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@
133133
import org.androidannotations.helper.ErrorHelper;
134134
import org.androidannotations.helper.Option;
135135
import org.androidannotations.helper.TimeStats;
136+
import org.androidannotations.logger.Logger;
137+
import org.androidannotations.logger.LoggerFactory;
136138
import org.androidannotations.model.AndroidRes;
137139
import org.androidannotations.model.AndroidSystemServices;
138140
import org.androidannotations.model.AnnotationElements;
@@ -287,17 +289,20 @@
287289
@SupportedOptions({ TRACE_OPTION, ANDROID_MANIFEST_FILE_OPTION, RESOURCE_PACKAGE_NAME_OPTION })
288290
public class AndroidAnnotationProcessor extends AbstractProcessor {
289291

292+
private static final Logger LOGGER = LoggerFactory.getLogger(AndroidAnnotationProcessor.class);
293+
290294
private final Properties properties = new Properties();
291295
private final Properties propertiesApi = new Properties();
292296
private final TimeStats timeStats = new TimeStats();
293297
private final ErrorHelper errorHelper = new ErrorHelper();
294-
295298
private Set<String> supportedAnnotationNames;
296299

297300
@Override
298301
public synchronized void init(ProcessingEnvironment processingEnv) {
299302
super.init(processingEnv);
300303

304+
LOGGER.warn("test: {}", processingEnv);
305+
301306
Messager messager = processingEnv.getMessager();
302307

303308
try {
@@ -642,6 +647,8 @@ private void generateSources(ProcessResult processResult) throws IOException {
642647
private void handleException(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv, ProcessingException e) {
643648
String errorMessage = errorHelper.getErrorMessage(processingEnv, e, getAAProcessorVersion());
644649

650+
LOGGER.error("Something went wront : {}", errorMessage);
651+
645652
Messager messager = processingEnv.getMessager();
646653
messager.printMessage(Diagnostic.Kind.ERROR, errorMessage);
647654

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package org.androidannotations.logger;
2+
3+
import java.io.PrintWriter;
4+
import java.io.StringWriter;
5+
import java.text.DateFormat;
6+
import java.text.SimpleDateFormat;
7+
import java.util.Arrays;
8+
import java.util.Date;
9+
10+
public class Formatter {
11+
12+
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss.S");
13+
private static final String ARGS_PATTERN = "{}";
14+
private static final int ARGS_PATTERN_LENGTH = ARGS_PATTERN.length();
15+
16+
public static String buildLog(Level level, String loggerName, String message, Throwable thr, Object... args) {
17+
String fullMessage = buildFullMessage(message, args);
18+
StringBuilder stringBuilder = new StringBuilder(fullMessage.length());
19+
20+
stringBuilder.append(DATE_FORMAT.format(new Date())) //
21+
.append(" [").append(Thread.currentThread().getName()).append("] ") //
22+
.append(" ").append(level.name) //
23+
.append(" ").append(loggerName) //
24+
.append(" - ").append(fullMessage);
25+
26+
// Stacktrace
27+
if (thr != null) {
28+
stringBuilder.append('\n').append(stackTraceToString(thr));
29+
}
30+
31+
stringBuilder.append('\n');
32+
33+
return stringBuilder.toString();
34+
}
35+
36+
public static String buildFullMessage(String message, Object... args) {
37+
StringBuilder stringBuilder = new StringBuilder(message.length());
38+
int lastIndex = 0;
39+
int argIndex = 0;
40+
41+
while (true) {
42+
int argPos = message.indexOf(ARGS_PATTERN, lastIndex);
43+
if (argPos == -1) {
44+
break;
45+
}
46+
47+
stringBuilder.append(message.substring(lastIndex, argPos));
48+
49+
lastIndex = argPos + ARGS_PATTERN_LENGTH;
50+
51+
// add the argument, if we still have any
52+
if (argIndex < args.length) {
53+
stringBuilder.append(formatArgument(args[argIndex]));
54+
argIndex++;
55+
}
56+
}
57+
58+
stringBuilder.append(message.substring(lastIndex));
59+
60+
return stringBuilder.toString();
61+
}
62+
63+
private static String formatArgument(Object arg) {
64+
if (arg != null && arg.getClass().isArray()) {
65+
return Arrays.toString((Object[]) arg);
66+
}
67+
return arg.toString();
68+
}
69+
70+
private static String stackTraceToString(Throwable e) {
71+
StringWriter writer = new StringWriter();
72+
PrintWriter pw = new PrintWriter(writer);
73+
e.printStackTrace(pw);
74+
return writer.toString();
75+
}
76+
77+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.androidannotations.logger;
2+
3+
public enum Level {
4+
TRACE(1, "TRACE"), //
5+
DEBUG(2, "DEBUG"), //
6+
INFO(3, "INFO "), //
7+
WARN(4, "WARN "), //
8+
ERROR(5, "ERROR");
9+
10+
public final int weight;
11+
public final String name;
12+
13+
private Level(int weight, String name) {
14+
this.weight = weight;
15+
this.name = name;
16+
}
17+
18+
public boolean isGreaterOrEqual(Level l) {
19+
return weight >= l.weight;
20+
}
21+
22+
}

0 commit comments

Comments
 (0)