Example usage for android.util Log println

List of usage examples for android.util Log println

Introduction

In this page you can find the example usage for android.util Log println.

Prototype

public static int println(int priority, String tag, String msg) 

Source Link

Document

Low-level logging call.

Usage

From source file:com.kth.common.utils.etc.LogUtil.java

/**
 * DEBUG  ?.//from ww  w .j  a  v  a 2  s.  c om
 * 
 * @param clazz  ??  Class.
 * @param msg .
 */
public static void d(final Class<?> clazz, final String msg) {
    if (LogUtil.isDebugEnabled()) {
        Log.println(Log.DEBUG, TAG, LogUtil.getClassLineNumber(clazz) + " - " + msg);

        //  ?? ?   ?.
        if (LogUtil.isFileLogEnabled()) {
            write(Log.DEBUG, LogUtil.getClassLineNumber(clazz), msg);
        }
    }
}

From source file:com.morphoss.acal.service.UpdateTimezones.java

private void refreshTimezoneData() {
    try {/*w w  w . j  a va  2s  .c o m*/
        HashMap<String, Long> currentZones = new HashMap<String, Long>();
        HashMap<String, Long> updatedZones = new HashMap<String, Long>();
        HashMap<String, Long> insertedZones = new HashMap<String, Long>();
        Cursor allZones = cr.query(Timezones.CONTENT_URI,
                new String[] { Timezones.TZID, Timezones.LAST_MODIFIED }, null, null, null);
        Long maxModified = 0L;
        for (allZones.moveToFirst(); !allZones.isAfterLast(); allZones.moveToNext()) {
            if (Constants.LOG_VERBOSE)
                Log.println(Constants.LOGV, TAG, "Found existing zone of '" + allZones.getString(0)
                        + "' modified: " + AcalDateTime.fromMillis(allZones.getLong(1) * 1000L).toString());
            currentZones.put(allZones.getString(0), allZones.getLong(1));
            if (allZones.getLong(1) > maxModified)
                maxModified = allZones.getLong(1);
        }
        AcalDateTime mostRecentChange = AcalDateTime.getUTCInstance().setEpoch(maxModified);
        Log.println(Constants.LOGI, TAG, "Found " + allZones.getCount()
                + " existing timezones, most recent change on " + mostRecentChange.toString());
        if (allZones.getCount() > 350 && mostRecentChange.after(AcalDateTime.getUTCInstance().addDays(-30))) {
            Log.println(Constants.LOGI, TAG, "Skipping update - our database is pretty recent");
            return;
        }

        requestor.interpretUriString(tzUrl("list", null));
        JSONObject root = requestor.doJsonRequest("GET", null, null, null);
        if (requestor.wasRedirected()) {
            Uri tzUri = Uri.parse(requestor.fullUrl());
            String redirectedUrl = tzUri.getScheme() + "://" + tzUri.getAuthority() + tzUri.getPath();
            if (Constants.debugTimeZone && Constants.LOG_DEBUG)
                Log.println(Constants.LOGD, TAG, "Redirected to Timezone Server at " + redirectedUrl);
            tzServerBaseUrl = redirectedUrl;
            AcalApplication.setPreferenceString(PrefNames.tzServerBaseUrl, redirectedUrl);
        }
        if (requestor.getStatusCode() >= 399) {
            Log.println(Constants.LOGI, TAG, "Bad response " + requestor.getStatusCode()
                    + " from Timezone Server at " + tzUrl("list", null));
        }
        if (root == null) {
            Log.println(Constants.LOGI, TAG, "No JSON from GET " + tzUrl("list", null));
            return;
        }

        String tzid;
        String tzData = "";
        long lastModified;
        StringBuilder localNames;
        StringBuilder aliases;
        ContentValues zoneValues = new ContentValues();

        String tzDateStamp = root.getString("dtstamp");
        JSONArray tzArray = root.getJSONArray("timezones");
        for (int i = 0; i < tzArray.length(); i++) {
            JSONObject zoneNode = tzArray.getJSONObject(i);
            tzid = zoneNode.getString("tzid");
            if (updatedZones.containsKey(tzid) || insertedZones.containsKey(tzid))
                continue;

            if (Constants.debugTimeZone && Constants.LOG_DEBUG)
                Log.println(Constants.LOGD, TAG, "Working on " + tzid);

            lastModified = AcalDateTime.fromString(zoneNode.getString("last-modified")).getEpoch();
            if (currentZones.containsKey(tzid) && currentZones.get(tzid) <= lastModified) {
                currentZones.remove(tzid);
                continue;
            }

            tzData = getTimeZone(tzid);
            if (tzData == null)
                continue;

            localNames = new StringBuilder();
            try {
                JSONArray nameNodes = zoneNode.getJSONArray("local_names");
                for (int j = 0; j < nameNodes.length(); j++) {
                    if (localNames.length() > 0)
                        localNames.append("\n");
                    localNames.append(nameNodes.getJSONObject(j).getString("lang")).append('~')
                            .append(nameNodes.getJSONObject(j).getString("lname"));
                }
            } catch (JSONException je) {
            }

            aliases = new StringBuilder();
            try {
                JSONArray aliasNodes = zoneNode.getJSONArray("aliases");
                for (int j = 0; j < aliasNodes.length(); j++) {
                    if (aliases.length() > 0)
                        aliases.append("\n");
                    aliases.append(aliasNodes.getString(j));
                }
            } catch (JSONException je) {
            }

            zoneValues.put(Timezones.TZID, tzid);
            zoneValues.put(Timezones.ZONE_DATA, tzData);
            zoneValues.put(Timezones.LAST_MODIFIED, lastModified);
            zoneValues.put(Timezones.TZ_NAMES, localNames.toString());
            zoneValues.put(Timezones.TZID_ALIASES, aliases.toString());

            Uri tzUri = Uri.withAppendedPath(Timezones.CONTENT_URI,
                    "tzid/" + StaticHelpers.urlescape(tzid, false));

            if (currentZones.containsKey(tzid)) {
                if (cr.update(tzUri, zoneValues, null, null) != 1) {
                    Log.e(TAG, "Failed update for TZID '" + tzid + "'");
                }
                updatedZones.put(tzid, currentZones.get(tzid));
                currentZones.remove(tzid);
            } else {
                if (cr.insert(tzUri, zoneValues) == null)
                    Log.e(TAG, "Failed insert for TZID '" + tzid + "'");
                insertedZones.put(tzid, currentZones.get(tzid));
            }

            if (context.workWaiting()) {
                Log.println(Constants.LOGI, TAG, "Something is waiting - deferring timezone sync until later.");
                deferMe = true;
                break;
            }
            // Let other stuff have a chance
            Thread.sleep(350);
        }
        int removed = 0;

        if (currentZones.size() > 0) {
            StringBuilder s = new StringBuilder();
            for (String tz : currentZones.keySet()) {
                if (s.length() > 0)
                    s.append(',');
                s.append("'").append(tz).append("'");
            }
            removed = cr.delete(Timezones.CONTENT_URI, Timezones.TZID + " IN (" + s + ")", null);
        }

        Log.println(Constants.LOGI, TAG, "Updated data for " + updatedZones.size() + " zones, added data for "
                + insertedZones.size() + " new zones, removed data for " + removed);
    } catch (Exception e) {
        Log.e(TAG, Log.getStackTraceString(e));
    }
}

From source file:com.kth.common.utils.etc.LogUtil.java

/**
 * DEBUG  ?./*from   w  w  w  .  j a  v a 2 s.c o m*/
 * 
 * @param clazz  ??  Class.
 * @param tr Throwable.
 */
public static void d(final Class<?> clazz, final Throwable tr) {
    if (LogUtil.isDebugEnabled()) {
        Log.println(Log.DEBUG, TAG, LogUtil.getClassLineNumber(clazz) + " - " + Log.getStackTraceString(tr));

        //  ?? ?   ?.
        if (LogUtil.isFileLogEnabled()) {
            write(Log.DEBUG, LogUtil.getClassLineNumber(clazz), tr);
        }
    }
}

From source file:com.kth.common.utils.etc.LogUtil.java

/**
 * DEBUG  ?.//from   w  ww . ja  va2  s.c  o m
 * 
 * @param clazz  ??  Class.
 * @param msg .
 * @param tr Throwable.
 */
public static void d(final Class<?> clazz, final String msg, final Throwable tr) {
    if (LogUtil.isDebugEnabled()) {
        Log.println(Log.DEBUG, TAG,
                LogUtil.getClassLineNumber(clazz) + " - " + msg + '\n' + Log.getStackTraceString(tr));

        //  ?? ?   ?.
        if (LogUtil.isFileLogEnabled()) {
            write(Log.DEBUG, LogUtil.getClassLineNumber(clazz), msg, tr);
        }
    }
}

From source file:org.fs.core.AbstractActivity.java

protected void log(final int lv, final String str) {
    if (isLogEnabled()) {
        Log.println(lv, getClassTag(), str);
    }/* ww w .  j  a  va2 s. co m*/
}

From source file:com.kth.common.utils.etc.LogUtil.java

/**
 * INFO  ?./*from   ww w .j  a va 2s . c  o m*/
 * 
 * @param clazz  ??  Class.
 * @param msg .
 */
public static void i(final Class<?> clazz, final String msg) {
    if (LogUtil.isInfoEnabled()) {
        Log.println(Log.INFO, TAG, LogUtil.getClassLineNumber(clazz) + " - " + msg);

        //  ?? ?   ?.
        if (LogUtil.isFileLogEnabled()) {
            write(Log.INFO, LogUtil.getClassLineNumber(clazz), msg);
        }
    }
}

From source file:org.openmidaas.library.MIDaaS.java

private static void log(int logLevel, String tag, String message, Throwable throwable) {
    if (logLevel >= currentLoggingLevel) {
        if (throwable == null) {
            Log.println(logLevel, tag, message);
        } else {//from w  ww. j  a va  2s  .c om
            Log.println(logLevel, tag, (new StringBuilder()).append(message).append("\n")
                    .append(throwable.getMessage()).toString());
        }
    }
}

From source file:com.kth.common.utils.etc.LogUtil.java

/**
 * INFO  ?.//from   ww  w .j a  v a2s  .co m
 * 
 * @param clazz  ??  Class.
 * @param tr Throwable.
 */
public static void i(final Class<?> clazz, final Throwable tr) {
    if (LogUtil.isInfoEnabled()) {
        Log.println(Log.INFO, TAG, LogUtil.getClassLineNumber(clazz) + " - " + Log.getStackTraceString(tr));

        //  ?? ?   ?.
        if (LogUtil.isFileLogEnabled()) {
            write(Log.INFO, LogUtil.getClassLineNumber(clazz), tr);
        }
    }
}

From source file:com.kth.common.utils.etc.LogUtil.java

/**
 * INFO  ?./*w  ww  .j  ava2s.c om*/
 * 
 * @param clazz  ??  Class.
 * @param msg .
 * @param tr Throwable.
 */
public static void i(final Class<?> clazz, final String msg, final Throwable tr) {
    if (LogUtil.isInfoEnabled()) {
        Log.println(Log.INFO, TAG,
                LogUtil.getClassLineNumber(clazz) + " - " + msg + '\n' + Log.getStackTraceString(tr));

        //  ?? ?   ?.
        if (LogUtil.isFileLogEnabled()) {
            write(Log.INFO, LogUtil.getClassLineNumber(clazz), msg, tr);
        }
    }
}

From source file:com.kth.common.utils.etc.LogUtil.java

/**
 * WARN  ?.//w  ww  . j  a va  2  s . c o m
 * 
 * @param clazz  ??  Class.
 * @param msg .
 */
public static void w(final Class<?> clazz, final String msg) {
    if (LogUtil.isWarnEnabled()) {
        Log.println(Log.WARN, TAG, LogUtil.getClassLineNumber(clazz) + " - " + msg);

        //  ?? ?   ?.
        if (LogUtil.isFileLogEnabled()) {
            write(Log.WARN, LogUtil.getClassLineNumber(clazz), msg);
        }
    }
}