~ubuntu-branches/ubuntu/utopic/libjaudiotagger-java/utopic

« back to all changes in this revision

Viewing changes to src/org/jaudiotagger/logging/LogFormatter.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-04-28 23:52:43 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110428235243-pzalvw6lncis3ukf
Tags: 2.0.3-1
* d/control: Drop Depends on default-jre per Debian Java Policy as its
  a library package.
* d/watch: Fix to directly monitor SVN tags.
* Switch to 3.0 (quilt) format.
* Bump Standards-Version to 3.9.2 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.jaudiotagger.logging;
2
 
 
3
 
import java.io.PrintWriter;
4
 
import java.io.StringWriter;
5
 
import java.text.SimpleDateFormat;
6
 
import java.util.Date;
7
 
import java.util.logging.Formatter;
8
 
import java.util.logging.LogRecord;
9
 
 
10
 
/**
11
 
 * For Formatting log output
12
 
 * <p/>
13
 
 * <p>This is not required by jaudiotagger, but its advantage over the default formatter is that all the format for a log
14
 
 * entry is on one line, making it much easier to read. To use this formatter with your code edit loggin.properties
15
 
 * within your jre/lib folder and  modify as follows
16
 
 * e.g java.util.logging.ConsoleHandler.formatter = org.jaudiotagger.logging.LogFormatter </p>
17
 
 */
18
 
public final class LogFormatter extends Formatter
19
 
{
20
 
    private boolean isObsfucated = false;
21
 
    public static final String ACTION_PERFORMED = "actionPerformed";
22
 
 
23
 
    // Line separator string.  This is the value of the line.separator
24
 
    // property at the moment that the SimpleFormatter was created.
25
 
    private final String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.
26
 
            GetPropertyAction("line.separator"));
27
 
 
28
 
    private final SimpleDateFormat sfDateOut = new SimpleDateFormat("dd/MM/yyyy HH.mm.ss:");
29
 
    private final Date date = new Date();
30
 
 
31
 
    public LogFormatter()
32
 
    {
33
 
 
34
 
    }
35
 
 
36
 
    public final String format(final LogRecord record)
37
 
    {
38
 
        final StringBuffer sb = new StringBuffer();
39
 
 
40
 
        date.setTime(record.getMillis());
41
 
 
42
 
        sb.append(sfDateOut.format(date));
43
 
 
44
 
        String recordName;
45
 
 
46
 
        if (record.getSourceClassName() != null)
47
 
        {
48
 
            recordName = record.getSourceClassName() + ":" + record.getSourceMethodName();
49
 
        }
50
 
        else
51
 
        {
52
 
            recordName = record.getLoggerName() + ":";
53
 
        }
54
 
        if (recordName != null)
55
 
        {
56
 
            sb.append(recordName);
57
 
            sb.append(":");
58
 
        }
59
 
        final String message = formatMessage(record);
60
 
        sb.append(record.getLevel().getLocalizedName());
61
 
        sb.append(": ");
62
 
        sb.append(message);
63
 
        sb.append(lineSeparator);
64
 
 
65
 
        if (record.getThrown() != null)
66
 
        {
67
 
            try
68
 
            {
69
 
                final StringWriter sw = new StringWriter();
70
 
                final PrintWriter pw = new PrintWriter(sw);
71
 
                record.getThrown().printStackTrace(pw);
72
 
                pw.close();
73
 
                sb.append(sw.toString());
74
 
            }
75
 
            catch (Exception ex)
76
 
            {
77
 
            }
78
 
        }
79
 
        return sb.toString();
80
 
    }
81
 
 
82
 
    public static final String IDENT = "$Id: LogFormatter.java,v 1.12 2009/11/12 15:42:59 paultaylor Exp $";
83
 
}
84
 
 
 
1
package org.jaudiotagger.logging;
 
2
 
 
3
import java.io.PrintWriter;
 
4
import java.io.StringWriter;
 
5
import java.text.SimpleDateFormat;
 
6
import java.util.Date;
 
7
import java.util.logging.Formatter;
 
8
import java.util.logging.LogRecord;
 
9
 
 
10
/**
 
11
 * For Formatting log output
 
12
 * <p/>
 
13
 * <p>This is not required by jaudiotagger, but its advantage over the default formatter is that all the format for a log
 
14
 * entry is on one line, making it much easier to read. To use this formatter with your code edit loggin.properties
 
15
 * within your jre/lib folder and  modify as follows
 
16
 * e.g java.util.logging.ConsoleHandler.formatter = org.jaudiotagger.logging.LogFormatter </p>
 
17
 */
 
18
public final class LogFormatter extends Formatter
 
19
{
 
20
    private boolean isObsfucated = false;
 
21
    public static final String ACTION_PERFORMED = "actionPerformed";
 
22
 
 
23
    // Line separator string.  This is the value of the line.separator
 
24
    // property at the moment that the SimpleFormatter was created.
 
25
    private final String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.
 
26
            GetPropertyAction("line.separator"));
 
27
 
 
28
    private final SimpleDateFormat sfDateOut = new SimpleDateFormat("dd/MM/yyyy HH.mm.ss:");
 
29
    private final Date date = new Date();
 
30
 
 
31
    public LogFormatter()
 
32
    {
 
33
 
 
34
    }
 
35
 
 
36
    public final String format(final LogRecord record)
 
37
    {
 
38
        final StringBuffer sb = new StringBuffer();
 
39
 
 
40
        date.setTime(record.getMillis());
 
41
 
 
42
        sb.append(sfDateOut.format(date));
 
43
 
 
44
        String recordName;
 
45
 
 
46
        if (record.getSourceClassName() != null)
 
47
        {
 
48
            recordName = record.getSourceClassName() + ":" + record.getSourceMethodName();
 
49
        }
 
50
        else
 
51
        {
 
52
            recordName = record.getLoggerName() + ":";
 
53
        }
 
54
        if (recordName != null)
 
55
        {
 
56
            sb.append(recordName);
 
57
            sb.append(":");
 
58
        }
 
59
        final String message = formatMessage(record);
 
60
        sb.append(record.getLevel().getLocalizedName());
 
61
        sb.append(": ");
 
62
        sb.append(message);
 
63
        sb.append(lineSeparator);
 
64
 
 
65
        if (record.getThrown() != null)
 
66
        {
 
67
            try
 
68
            {
 
69
                final StringWriter sw = new StringWriter();
 
70
                final PrintWriter pw = new PrintWriter(sw);
 
71
                record.getThrown().printStackTrace(pw);
 
72
                pw.close();
 
73
                sb.append(sw.toString());
 
74
            }
 
75
            catch (Exception ex)
 
76
            {
 
77
            }
 
78
        }
 
79
        return sb.toString();
 
80
    }
 
81
 
 
82
    public static final String IDENT = "$Id: LogFormatter.java 836 2009-11-12 15:44:07Z paultaylor $";
 
83
}
 
84