1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: String formatter for log files |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.tools.themeinstaller.logger; |
|
20 |
|
21 import java.text.SimpleDateFormat; |
|
22 import java.util.Date; |
|
23 import java.util.logging.Formatter; |
|
24 import java.util.logging.Handler; |
|
25 import java.util.logging.LogRecord; |
|
26 |
|
27 /** |
|
28 * Formats logging string to human readable form. |
|
29 */ |
|
30 public class LogFormatter extends Formatter |
|
31 { |
|
32 // Format for date and time. |
|
33 private final static String DATE_FORMAT = "dd/MM/yyyy HH:mm:ss"; |
|
34 |
|
35 /* (non-Javadoc) |
|
36 * @see java.util.logging.Formatter#format(java.util.logging.LogRecord) |
|
37 */ |
|
38 public String format( LogRecord aRec ) |
|
39 { |
|
40 return ( dateToString( DATE_FORMAT, aRec.getMillis() ) + " " + aRec.getLevel() + " " |
|
41 + formatMessage( aRec ) + "\n" ); |
|
42 } |
|
43 |
|
44 /* (non-Javadoc) |
|
45 * @see java.util.logging.Formatter#getHead(java.util.logging.Handler) |
|
46 */ |
|
47 public String getHead( Handler aHandler ) |
|
48 { |
|
49 return ""; |
|
50 } |
|
51 |
|
52 /* (non-Javadoc) |
|
53 * @see java.util.logging.Formatter#getTail(java.util.logging.Handler) |
|
54 */ |
|
55 public String getTail( Handler aHandler ) |
|
56 { |
|
57 return ""; |
|
58 } |
|
59 |
|
60 /** |
|
61 * Formats date and time to string based on expression aFormat. |
|
62 * |
|
63 * @param aFormat expression for date and time |
|
64 * |
|
65 * @return Date and time in formatted string |
|
66 */ |
|
67 public static String dateToString( String aFormat, long aDateMillis ) |
|
68 { |
|
69 SimpleDateFormat sdf = new SimpleDateFormat( aFormat ); |
|
70 String dateString = sdf.format( new Date( aDateMillis ) ).toString(); |
|
71 return dateString; |
|
72 } |
|
73 |
|
74 } |
|