1/* 2 * Copyright (c) 2022 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#include "util/logger.h" 17 18#include <cstdio> 19 20namespace OHOS { 21namespace Idl { 22int Logger::level_ = DEBUG; 23 24void Logger::D(const char* tag, const char* format, ...) 25{ 26 if (level_ > DEBUG) return; 27 28 va_list args; 29 va_start(args, format); 30 Log(tag, format, args); 31 va_end(args); 32} 33 34void Logger::E(const char* tag, const char* format, ...) 35{ 36 if (level_ > ERROR) return; 37 38 va_list args; 39 va_start(args, format); 40 Err(tag, format, args); 41 va_end(args); 42} 43 44void Logger::V(const char* tag, const char* format, ...) 45{ 46 if (level_ > VERBOSE) return; 47 48 va_list args; 49 va_start(args, format); 50 Log(tag, format, args); 51 va_end(args); 52} 53 54void Logger::Log(const char* tag, const char* format, va_list args) 55{ 56 printf("[%s]: ", tag); 57 vprintf(format, args); 58 printf("\n"); 59} 60 61void Logger::Err(const char* tag, const char* format, va_list args) 62{ 63 fprintf(stderr, "[%s]: ", tag); 64 vfprintf(stderr, format, args); 65 fprintf(stderr, "\n"); 66} 67} 68} 69