themeinstaller/source/src/com/nokia/tools/themeinstaller/logger/LogFormatter.java
branchRCL_3
changeset 18 04b7640f6fb5
parent 0 05da4621cfb2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/themeinstaller/source/src/com/nokia/tools/themeinstaller/logger/LogFormatter.java	Wed Sep 01 12:32:13 2010 +0100
@@ -0,0 +1,74 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  String formatter for log files
+ *
+*/
+
+
+package com.nokia.tools.themeinstaller.logger;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+
+/**
+ * Formats logging string to human readable form.
+ */
+public class LogFormatter extends Formatter
+    {
+    // Format for date and time.
+    private final static String DATE_FORMAT = "dd/MM/yyyy HH:mm:ss";
+
+    /* (non-Javadoc)
+     * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
+     */
+    public String format( LogRecord aRec )
+        {
+        return ( dateToString( DATE_FORMAT, aRec.getMillis() ) + " " + aRec.getLevel() + " "
+                + formatMessage( aRec ) + "\n" );
+        }
+
+    /* (non-Javadoc)
+     * @see java.util.logging.Formatter#getHead(java.util.logging.Handler)
+     */
+    public String getHead( Handler aHandler )
+        {
+        return "";
+        }
+
+    /* (non-Javadoc)
+     * @see java.util.logging.Formatter#getTail(java.util.logging.Handler)
+     */
+    public String getTail( Handler aHandler )
+        {
+        return "";
+        }
+
+    /**
+     * Formats date and time to string based on expression aFormat.
+     *
+     * @param aFormat expression for date and time
+     *
+     * @return Date and time in formatted string
+     */
+    public static String dateToString( String aFormat, long aDateMillis )
+        {
+        SimpleDateFormat sdf = new SimpleDateFormat( aFormat );
+        String dateString = sdf.format( new Date( aDateMillis ) ).toString();
+        return dateString;
+        }
+
+    }