From 14c4caea141405eb7d378079d9b1b69f92d6c2c7 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 31 Oct 2012 23:50:02 +1300 Subject: Improve logging methods --- src/org/traccar/helper/Log.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java index ce99f959a..69eea6579 100644 --- a/src/org/traccar/helper/Log.java +++ b/src/org/traccar/helper/Log.java @@ -15,6 +15,7 @@ */ package org.traccar.helper; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -28,21 +29,30 @@ public class Log { public static Logger getLogger() { return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); } + + private static void write(Level level, String msg) { + StackTraceElement[] stack = Thread.currentThread().getStackTrace(); + if (stack != null && stack.length > 3) { + getLogger().logp(level, stack[3].getClassName(), stack[3].getMethodName(), msg); + } else { + getLogger().log(level, msg); + } + } public static void severe(String msg) { - getLogger().severe(msg); + write(Level.SEVERE, msg); } public static void warning(String msg) { - getLogger().warning(msg); + write(Level.WARNING, msg); } public static void info(String msg) { - getLogger().info(msg); + write(Level.INFO, msg); } public static void fine(String msg) { - getLogger().fine(msg); + write(Level.FINE, msg); } } -- cgit v1.2.3