If you think the Android project JsonPullParser listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2011 vvakame <vvakame@gmail.com>
*//www.java2s.com
* 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 net.vvakame.util.jsonpullparser.factory;
import javax.annotation.processing.Messager;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic;
/**
* Logging facility modelled after Android's Log class.
* @author vvakame
*/publicclass Log {
static Messager messager = null;
staticboolean debug = false;
/**
* Initialization.
* @param msgr
* @author vvakame
*/publicstaticvoid init(Messager msgr) {
messager = msgr;
}
/**
* Enables or disables debugging mode.
* @param d True to enable, false to disable
* @author vvakame
*/publicstaticvoid setDebug(boolean d) {
debug = d;
}
/**
* Logs debug message.<br>
* No-op if the debugging mode ({@link #debug}) is disabled.
* @author vvakame
*/publicstaticvoid d() {
if (!debug) {
return;
}
d(getStackInfo());
}
/**
* Logs debug message.<br>
* No-op if the debugging mode ({@link #debug}) is disabled.
* @param msg Message
* @author vvakame
*/publicstaticvoid d(String msg) {
if (!debug) {
return;
}
if (messager == null) {
return;
}
messager.printMessage(Diagnostic.Kind.NOTE, msg);
}
/**
* Logs warning message.
* @param msg Message
* @author vvakame
*/publicstaticvoid w(String msg) {
messager.printMessage(Diagnostic.Kind.WARNING, msg);
}
/**
* Logs warning message about the given element.<br>
* @param msg Message
* @param element Offending element
* @author vvakame
*/publicstaticvoid w(String msg, Element element) {
messager.printMessage(Diagnostic.Kind.WARNING, msg, element);
}
/**
* Logs error message.
* @param msg Message
* @author vvakame
*/publicstaticvoid e(String msg) {
messager.printMessage(Diagnostic.Kind.ERROR, msg);
}
/**
* Logs error message about the given element.
* @param msg Message
* @param element Offending element
* @author vvakame
*/publicstaticvoid e(String msg, Element element) {
messager.printMessage(Diagnostic.Kind.ERROR, msg, element);
}
/**
* Logs error message about the given exception.
* @param e Offending throwable
* @author vvakame
*/publicstaticvoid e(Throwable e) {
messager.printMessage(Diagnostic.Kind.ERROR, "exception thrown! " + e.getMessage());
}
static String getStackInfo() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (StackTraceElement stack : stackTrace) {
if (Thread.class.getCanonicalName().equals(stack.getClassName())) {
continue;
} elseif (Log.class.getCanonicalName().equals(stack.getClassName())) {
continue;
} else {
return stack.getClassName() + "#" + stack.getMethodName() + "@L"
+ stack.getLineNumber();
}
}
return"unknown";
}
}