Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
LoggerContext loggerContext = LoggerContext.getInstance();
loggerContext.setProcessingEnv(processingEnv);

LOGGER.info("Initialize AndroidAnnotationProcessor with options {}", processingEnv.getOptions());

try {
loadPropertyFile();
loadApiPropertyFile();
} catch (Exception e) {
LOGGER.error("Can't load API or core properties files", e);
}

LOGGER.info("Initialize AndroidAnnotations {} with options {}", getAAProcessorVersion(), processingEnv.getOptions());

annotationHandlers = new AnnotationHandlers(processingEnv);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.androidannotations.logger.appender.ConsoleAppender;
import org.androidannotations.logger.appender.FileAppender;
import org.androidannotations.logger.appender.MessagerAppender;
import org.androidannotations.logger.formatter.Formatter;

public class LoggerContext {

Expand All @@ -35,7 +36,6 @@ public class LoggerContext {

private Level currentLevel = DEFAULT_LEVEL;
private List<Appender> appenders = new ArrayList<Appender>();
private Formatter formatter = new Formatter();

public static LoggerContext getInstance() {
if (INSTANCE == null) {
Expand All @@ -54,8 +54,9 @@ public static LoggerContext getInstance() {
}

public void writeLog(Level level, String loggerName, String message, Element element, AnnotationMirror annotationMirror, Throwable thr, Object... args) {
String log = formatter.buildLog(level, loggerName, message, thr, args);
for (Appender appender : appenders) {
Formatter formatter = appender.getFormatter();
String log = formatter.buildLog(level, loggerName, message, thr, args);
appender.append(level, element, annotationMirror, log);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@

import org.androidannotations.helper.OptionsHelper;
import org.androidannotations.logger.Level;
import org.androidannotations.logger.formatter.Formatter;

public abstract class Appender {

protected final Formatter formatter;
protected ProcessingEnvironment processingEnv;
protected OptionsHelper optionsHelper;

public Appender(Formatter formatter) {
this.formatter = formatter;
}

public Formatter getFormatter() {
return formatter;
}

public void setProcessingEnv(ProcessingEnvironment processingEnv) {
this.processingEnv = processingEnv;
optionsHelper = new OptionsHelper(processingEnv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
import javax.lang.model.element.Element;

import org.androidannotations.logger.Level;
import org.androidannotations.logger.formatter.FormatterFull;

public class ConsoleAppender extends Appender {

public ConsoleAppender() {
super(new FormatterFull());
}

@Override
public void open() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.androidannotations.helper.FileHelper;
import org.androidannotations.logger.Level;
import org.androidannotations.logger.formatter.FormatterFull;

public class FileAppender extends Appender {

Expand All @@ -36,6 +37,10 @@ public class FileAppender extends Appender {
private File file;
private FileOutputStream outputStream;

public FileAppender() {
super(new FormatterFull());
}

@Override
public synchronized void open() {
if (!isStreamOpened()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
import javax.tools.Diagnostic.Kind;

import org.androidannotations.logger.Level;
import org.androidannotations.logger.formatter.FormatterSimple;

public class MessagerAppender extends Appender {

public MessagerAppender() {
super(new FormatterSimple());
}

private Messager messager;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.logger;
package org.androidannotations.logger.formatter;

import java.io.PrintWriter;
import java.io.StringWriter;
Expand All @@ -22,32 +22,26 @@
import java.util.Arrays;
import java.util.Date;

public class Formatter {
import org.androidannotations.logger.Level;
import org.androidannotations.logger.Logger;

public abstract class Formatter {

private static final DateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss.S");
private static final String ARGS_PATTERN = "{}";
private static final int ARGS_PATTERN_LENGTH = ARGS_PATTERN.length();

public String buildLog(Level level, String loggerName, String message, Throwable thr, Object... args) {
String fullMessage = buildFullMessage(message, args);
StringBuilder stringBuilder = new StringBuilder(fullMessage.length());

stringBuilder.append(DATE_FORMAT.format(new Date())) //
.append(" [").append(Thread.currentThread().getName()).append("]") //
.append(" ").append(level.name) //
.append(" ").append(loggerName) //
.append(":").append(getCallerLineNumber()) //
.append(" - ").append(fullMessage);
public abstract String buildLog(Level level, String loggerName, String message, Throwable thr, Object... args);

// Stacktrace
if (thr != null) {
stringBuilder.append('\n').append(stackTraceToString(thr));
}
protected String getCurrentThread() {
return Thread.currentThread().getName();
}

return stringBuilder.toString();
protected String getTime() {
return DATE_FORMAT.format(new Date());
}

public String buildFullMessage(String message, Object... args) {
protected String buildFullMessage(String message, Object... args) {
StringBuilder stringBuilder = new StringBuilder(message.length());
int lastIndex = 0;
int argIndex = 0;
Expand All @@ -74,21 +68,21 @@ public String buildFullMessage(String message, Object... args) {
return stringBuilder.toString();
}

private String formatArgument(Object arg) {
protected String formatArgument(Object arg) {
if (arg != null && arg.getClass().isArray()) {
return Arrays.toString((Object[]) arg);
}
return arg.toString();
}

private String stackTraceToString(Throwable e) {
protected String stackTraceToString(Throwable e) {
StringWriter writer = new StringWriter();
PrintWriter pw = new PrintWriter(writer);
e.printStackTrace(pw);
return writer.toString();
}

private int getCallerLineNumber() {
protected int getCallerLineNumber() {
boolean previousWasLogger = false;
String loggerClassName = Logger.class.getCanonicalName();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (C) 2010-2013 eBusiness Information, Excilys Group
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.logger.formatter;

import org.androidannotations.logger.Level;

public class FormatterFull extends Formatter {

@Override
public String buildLog(Level level, String loggerName, String message, Throwable thr, Object... args) {
StringBuilder stringBuilder = new StringBuilder();

stringBuilder.append(getTime()) //
.append(" [").append(getCurrentThread()).append("]") //
.append(" ").append(level.name) //
.append(" ").append(loggerName) //
.append(":").append(getCallerLineNumber()) //
.append(" - ").append(buildFullMessage(message, args));

// Stacktrace
if (thr != null) {
stringBuilder.append('\n').append(stackTraceToString(thr));
}

return stringBuilder.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (C) 2010-2013 eBusiness Information, Excilys Group
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.logger.formatter;

import org.androidannotations.logger.Level;

public class FormatterSimple extends Formatter {

@Override
public String buildLog(Level level, String loggerName, String message, Throwable thr, Object... args) {
StringBuilder stringBuilder = new StringBuilder();

stringBuilder.append(buildFullMessage(message, args));

// Stacktrace
if (thr != null) {
stringBuilder.append('\n').append(stackTraceToString(thr));
}

return stringBuilder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.logger;
package org.androidannotations.logger.formatter;

import java.util.Arrays;
import java.util.List;
Expand All @@ -23,7 +23,7 @@

public class FormatterTest {

private Formatter formatter = new Formatter();
private Formatter formatter = new FormatterSimple();

class SomeObject {
String name;
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.