1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package com.update.check.log; 17 18 import org.apache.logging.log4j.LogManager; 19 20 /** 21 * The implementation class of {@link Logger}, based on Log4j. 22 * 23 * @since 23-04-07 24 */ 25 class LoggerImpl extends Logger { 26 private static final String MESSAGE_FORMAT = "[%s] %s - %s"; 27 28 private final org.apache.logging.log4j.Logger logger; 29 30 private final String prefix; 31 LoggerImpl()32 LoggerImpl() { 33 prefix = "updateCheck"; 34 logger = LogManager.getLogger(Logger.LOGGER_NAME); 35 } 36 37 @Override error(String tag, String message)38 public void error(String tag, String message) { 39 logger.error(String.format(MESSAGE_FORMAT, prefix, tag, message)); 40 } 41 42 @Override info(String tag, String message)43 public void info(String tag, String message) { 44 logger.info(String.format(MESSAGE_FORMAT, prefix, tag, message)); 45 } 46 47 @Override warn(String tag, String message)48 public void warn(String tag, String message) { 49 logger.warn(String.format(MESSAGE_FORMAT, prefix, tag, message)); 50 } 51 52 @Override debug(String tag, String message)53 public void debug(String tag, String message) { 54 logger.debug(String.format(MESSAGE_FORMAT, prefix, tag, message)); 55 } 56 57 }