001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.javabridge; 020 021import org.apache.reef.annotations.audience.Interop; 022import org.apache.reef.annotations.audience.Private; 023 024import java.util.HashMap; 025import java.util.logging.Level; 026import java.util.logging.Logger; 027 028/** 029 * Logger called from CLR code. 030 */ 031@Private 032@Interop(CppFiles = { "JavaClrBridge.cpp", "InteropLogger.h", "InteropLogger.cpp" }) 033public final class InteropLogger { 034 private static final Logger LOG = Logger.getLogger("InteropLogger"); 035 private HashMap<Integer, Level> levelHashMap; 036 037 { 038 levelHashMap = new HashMap<>(); 039 levelHashMap.put(Level.OFF.intValue(), Level.OFF); 040 levelHashMap.put(Level.SEVERE.intValue(), Level.SEVERE); 041 levelHashMap.put(Level.WARNING.intValue(), Level.WARNING); 042 levelHashMap.put(Level.INFO.intValue(), Level.INFO); 043 044 levelHashMap.put(Level.CONFIG.intValue(), Level.CONFIG); 045 levelHashMap.put(Level.FINE.intValue(), Level.FINE); 046 levelHashMap.put(Level.FINER.intValue(), Level.FINER); 047 048 levelHashMap.put(Level.FINEST.intValue(), Level.FINEST); 049 levelHashMap.put(Level.ALL.intValue(), Level.ALL); 050 } 051 052 public void log(final int intLevel, final String message) { 053 if (levelHashMap.containsKey(intLevel)) { 054 final Level level = levelHashMap.get(intLevel); 055 LOG.log(level, message); 056 } else { 057 LOG.log(Level.WARNING, "Level " + intLevel + " is not a valid Log level"); 058 LOG.log(Level.WARNING, message); 059 } 060 } 061}