OpenSplice Java FACE API  v6.x
OpenSplice Future Airborne Capability Environment (FACE) Java API
Logger.java
Go to the documentation of this file.
1 /*
2  * Vortex OpenSplice
3  *
4  * This software and documentation are Copyright 2006 to 2021 ADLINK
5  * Technology Limited, its affiliated companies and licensors. All rights
6  * reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 package org.vortex.FACE;
21 
22 import java.util.logging.Level;
23 
24 public class Logger {
25  private boolean enabled;
26  private Level level;
27 
28  private Logger() {
29  this.enabled = Boolean.parseBoolean(Util.getenv("FACE_LOGGING"));
30  try {
31  this.level = Level.parse(Util.getenv("FACE_LOGGING_LEVEL"));
32  } catch (NullPointerException npe) {
33  this.level = Level.ALL;
34  } catch (IllegalArgumentException iae) {
35  this.level = Level.ALL;
36  }
37  }
38 
39  private static class LazyHolder {
40  private static final Logger INSTANCE = new Logger();
41  }
42 
43  public static Logger getInstance() {
44  return LazyHolder.INSTANCE;
45  }
46 
47  public void log(String message, Level level) {
48  if (this.enabled) {
49  if (level.intValue() >= this.level.intValue()) {
50  System.err.println(message);
51  }
52  } else {
53  if (level.intValue() >= this.level.intValue()) {
54  org.opensplice.dds.dcps.ReportStack.start();
55  org.opensplice.dds.dcps.ReportStack.report(1, message);
56  org.opensplice.dds.dcps.ReportStack.flush(true);
57  }
58  }
59  }
60 
61  public void exception(Exception e) {
62  this.log(
63  e.getClass().getName() + " occurred: " + e.getMessage() + "\n",
64  Level.SEVERE);
65 
66  for (StackTraceElement ste : e.getStackTrace()) {
67  this.log(" at " + ste.getClassName() + "." + ste.getMethodName()
68  + "(" + ste.getFileName() + ":" + ste.getLineNumber()
69  + ")\n", Level.SEVERE);
70  }
71  }
72 }
void log(String message, Level level)
Definition: Logger.java:47
void exception(Exception e)
Definition: Logger.java:61
static Logger getInstance()
Definition: Logger.java:43
static String getenv(String name)
Definition: Util.java:26