Java Log to File log(String tag, T msg)

Here you can find the source of log(String tag, T msg)

Description

log

License

Apache License

Declaration

public static <T> void log(String tag, T msg) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss.SSS",
            Locale.getDefault());

    public static <T> void log(String tag, T msg) {
        print(DATE_FORMAT.format(new Date()));
        print("  ");
        if (isEmpty(tag)) {
            println(msg);//  www  .  jav a2s  .c o  m
        } else {
            println(tag + ": " + msg);
        }
    }

    public static <T> void print(T t) {
        System.out.print(t);
    }

    public static boolean isEmpty(String s) {
        return s == null || s.isEmpty();
    }

    public static void println() {
        System.out.println();
    }

    public static <T> void println(T t) {
        System.out.println(t);
    }
}

Related

  1. log(String message, Exception e)
  2. log(String method, String message)
  3. log(String msg)
  4. log(String msg)
  5. log(String name, String message)
  6. logError(ILog log, String message)
  7. logError(String message)
  8. logError(String msg)
  9. logErrPrint(String s)