1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <lk/trace.h> 20 21 enum { 22 TRACE_LEVEL_NONE, 23 TRACE_LEVEL_ERROR, 24 TRACE_LEVEL_WARNING, 25 TRACE_LEVEL_INIT, 26 TRACE_LEVEL_WRITE, 27 TRACE_LEVEL_READ, 28 }; 29 30 #define TRACEFF(f, str, x...) \ 31 do { \ 32 fprintf(f, "%s():%d: " str, __func__, __LINE__, ##x); \ 33 } while (0) 34 #undef LTRACEF_LEVEL 35 #define LTRACEF_LEVEL(level, x...) \ 36 do { \ 37 if (LOCAL_TRACE >= (level)) { \ 38 TRACEFF((LOCAL_TRACE_ERR >= level) ? stderr : stdout, x); \ 39 } \ 40 } while (0) 41 42 #ifndef LOCAL_TRACE 43 #define LOCAL_TRACE TRACE_LEVEL_WARNING 44 #endif 45 #ifndef LOCAL_TRACE_ERR 46 #define LOCAL_TRACE_ERR TRACE_LEVEL_ERROR 47 #endif 48 49 #define pr_err(x...) LTRACEF_LEVEL(TRACE_LEVEL_ERROR, x) 50 #define pr_warn(x...) LTRACEF_LEVEL(TRACE_LEVEL_WARNING, x) 51 #define pr_init(x...) LTRACEF_LEVEL(TRACE_LEVEL_INIT, x) 52 #define pr_write(x...) LTRACEF_LEVEL(TRACE_LEVEL_WRITE, x) 53 #define pr_read(x...) LTRACEF_LEVEL(TRACE_LEVEL_READ, x) 54