blob: 7b8aea437c5c0ac7458411b8da306f68c317044d [file] [log] [blame]
Felix Meschberger08282c32009-01-28 07:01:55 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.apache.felix.cm;
20
21
22import org.osgi.framework.ServiceReference;
23import org.osgi.service.log.LogService;
24
25
26/**
27 * The <code>MockLogService</code> is a very simple log service, which just
28 * prints the loglevel and message to StdErr.
29 */
30public class MockLogService implements LogService
31{
32
33 public void log( int logLevel, String message )
34 {
35 System.err.print( toMessageLine( logLevel, message ) );
36 }
37
38
39 public void log( int logLevel, String message, Throwable t )
40 {
41 log( logLevel, message );
42 }
43
44
45 public void log( ServiceReference ref, int logLevel, String message )
46 {
47 log( logLevel, message );
48 }
49
50
51 public void log( ServiceReference ref, int logLevel, String message, Throwable t )
52 {
53 log( logLevel, message );
54 }
55
56
57 /**
58 * Helper method to format log level and log message exactly the same as the
59 * <code>ConfigurationManager.log()</code> does.
60 */
61 public static String toMessageLine( int level, String message )
62 {
63 String messageLine;
64 switch ( level )
65 {
66 case LogService.LOG_INFO:
67 messageLine = "*INFO *";
68 break;
69
70 case LogService.LOG_WARNING:
71 messageLine = "*WARN *";
72 break;
73
74 case LogService.LOG_ERROR:
75 messageLine = "*ERROR*";
76 break;
77
78 case LogService.LOG_DEBUG:
79 default:
80 messageLine = "*DEBUG*";
81 }
82 return messageLine + " " + message + System.getProperty( "line.separator" );
83 }
84}