|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2011 by the original author(s). |
| 2 | + * Copyright 2011-2013 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
6 | 6 | * You may obtain a copy of the License at
|
7 | 7 | *
|
8 |
| - * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 | *
|
10 | 10 | * Unless required by applicable law or agreed to in writing, software
|
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 |
| - |
17 | 16 | package org.springframework.data.mongodb.log4j;
|
18 | 17 |
|
19 | 18 | import java.net.UnknownHostException;
|
|
34 | 33 | import com.mongodb.WriteConcern;
|
35 | 34 |
|
36 | 35 | /**
|
37 |
| - * @author Jon Brisbin <jbrisbin@vmware.com> |
| 36 | + * Log4j appender writing log entries into a MongoDB instance. |
| 37 | + * |
| 38 | + * @author Jon Brisbin |
| 39 | + * @author Oliver Gierke |
38 | 40 | */
|
39 | 41 | public class MongoLog4jAppender extends AppenderSkeleton {
|
40 | 42 |
|
@@ -130,8 +132,12 @@ protected void connectToMongo() throws UnknownHostException {
|
130 | 132 | this.db = mongo.getDB(database);
|
131 | 133 | }
|
132 | 134 |
|
133 |
| - @SuppressWarnings({ "unchecked" }) |
| 135 | + /* |
| 136 | + * (non-Javadoc) |
| 137 | + * @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent) |
| 138 | + */ |
134 | 139 | @Override
|
| 140 | + @SuppressWarnings({ "unchecked" }) |
135 | 141 | protected void append(final LoggingEvent event) {
|
136 | 142 | if (null == db) {
|
137 | 143 | try {
|
@@ -199,10 +205,21 @@ protected void append(final LoggingEvent event) {
|
199 | 205 | db.getCollection(coll).insert(dbo, wc);
|
200 | 206 | }
|
201 | 207 |
|
| 208 | + /* |
| 209 | + * (non-Javadoc) |
| 210 | + * @see org.apache.log4j.AppenderSkeleton#close() |
| 211 | + */ |
202 | 212 | public void close() {
|
203 |
| - mongo.close(); |
| 213 | + |
| 214 | + if (mongo != null) { |
| 215 | + mongo.close(); |
| 216 | + } |
204 | 217 | }
|
205 | 218 |
|
| 219 | + /* |
| 220 | + * (non-Javadoc) |
| 221 | + * @see org.apache.log4j.AppenderSkeleton#requiresLayout() |
| 222 | + */ |
206 | 223 | public boolean requiresLayout() {
|
207 | 224 | return true;
|
208 | 225 | }
|
|
0 commit comments