EMMA Coverage Report (generated Mon Mar 20 21:34:30 PST 2006)
[all classes][com.moesol.bindings.platform_sdk.debugging_and_error_handling]

COVERAGE SUMMARY FOR SOURCE FILE [EventLogHandler.java]

nameclass, %method, %block, %line, %
EventLogHandler.java100% (1/1)67%  (4/6)83%  (60/72)82%  (18/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EventLogHandler100% (1/1)67%  (4/6)83%  (60/72)82%  (18/22)
close (): void 0%   (0/1)0%   (0/1)0%   (0/1)
flush (): void 0%   (0/1)0%   (0/1)0%   (0/1)
publish (LogRecord): void 100% (1/1)69%  (22/32)75%  (6/8)
EventLogHandler (): void 100% (1/1)100% (11/11)100% (4/4)
ReportEvent (int, String): boolean 100% (1/1)100% (4/4)100% (1/1)
computeNtEventLogLevel (Level): int 100% (1/1)100% (23/23)100% (7/7)

1/*
2 * $Id: EventLogHandler.java,v 1.1 2006/03/07 17:52:10 hastings Exp $
3 *
4 * (c) Copyright, Moebius Solutions, Inc., 2004
5 *
6 *                       All Rights Reserved
7 *
8 * This material may be reproduced by or for the U. S. Government
9 * pursuant to the copyright license under the clause at
10 * DFARS 252.227-7014 (OCT 2001).
11 */
12package com.moesol.bindings.platform_sdk.debugging_and_error_handling;
13 
14import java.util.logging.ErrorManager;
15import java.util.logging.Formatter;
16import java.util.logging.Handler;
17import java.util.logging.Level;
18import java.util.logging.LogRecord;
19import java.util.logging.SimpleFormatter;
20 
21import com.moesol.bindings.platform_sdk.component_services.COMException;
22import com.moesol.bindings.platform_sdk.component_services.HRESULT;
23import com.moesol.bindings.platform_sdk.windows_api.PlatformSDK;
24 
25/**
26 * Copy java logging records to Windows Event Log.
27 * 
28 * @author Hastings
29 */
30public class EventLogHandler extends Handler {
31 
32        //
33        //         The types of events that can be logged.
34        //
35        public static final int EVENTLOG_SUCCESS                = 0x0000;
36        public static final int EVENTLOG_ERROR_TYPE             = 0x0001;
37        public static final int EVENTLOG_WARNING_TYPE           = 0x0002;
38        public static final int EVENTLOG_INFORMATION_TYPE       = 0x0004;
39        public static final int EVENTLOG_AUDIT_SUCCESS          = 0x0008;
40        public static final int EVENTLOG_AUDIT_FAILURE          = 0x0010;
41        
42        public EventLogHandler() {
43                super();
44                
45                if (getFormatter() == null) {
46                        setFormatter(new SimpleFormatter());
47                }
48        }
49        public void publish(LogRecord record) {
50                if (!isLoggable(record)) {
51                        return;
52                }
53                
54                Formatter fmt = getFormatter();
55                String msg = fmt.format(record);
56                int nt_eventlog_level = computeNtEventLogLevel(record.getLevel());
57                if (!ReportEvent(nt_eventlog_level, msg)) {
58                        reportError(
59                                        "ReportEvent failed", 
60                                        new COMException(HRESULT.HRESULT_FROM_NT(PlatformSDK.GetLastError())),
61                                        ErrorManager.WRITE_FAILURE 
62                        );
63                }
64        }
65 
66        private int computeNtEventLogLevel(Level level) {
67                if (level.intValue() >= Level.SEVERE.intValue()) {
68                        return EVENTLOG_ERROR_TYPE;
69                }
70                if (level.intValue() >= Level.WARNING.intValue()) {
71                        return EVENTLOG_WARNING_TYPE;
72                }
73                if (level.intValue() >= Level.INFO.intValue()) {
74                        return EVENTLOG_INFORMATION_TYPE;
75                }
76                
77                return EVENTLOG_SUCCESS;
78        }
79        
80        private boolean ReportEvent(int nt_eventlog_level, String msg) {
81                return jni_ReportEvent(nt_eventlog_level, msg);
82        }
83        
84        private static native boolean jni_ReportEvent(int nt_eventlog_level, String msg);
85 
86        public void flush() {
87                // done
88        }
89 
90        public void close() throws SecurityException {
91                // done
92        }
93 
94}

[all classes][com.moesol.bindings.platform_sdk.debugging_and_error_handling]
EMMA 2.0.5312 (C) Vladimir Roubtsov