17ec681f3Smrg/* 27ec681f3Smrg * Copyright 2017 Google 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 97ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 217ec681f3Smrg * IN THE SOFTWARE. 227ec681f3Smrg */ 237ec681f3Smrg 247ec681f3Smrg#ifndef MESA_LOG_H 257ec681f3Smrg#define MESA_LOG_H 267ec681f3Smrg 277ec681f3Smrg#include <stdarg.h> 287ec681f3Smrg 297ec681f3Smrg#include "util/macros.h" 307ec681f3Smrg 317ec681f3Smrg#ifdef __cplusplus 327ec681f3Smrgextern "C" { 337ec681f3Smrg#endif 347ec681f3Smrg 357ec681f3Smrg#ifndef MESA_LOG_TAG 367ec681f3Smrg#define MESA_LOG_TAG "MESA" 377ec681f3Smrg#endif 387ec681f3Smrg 397ec681f3Smrgenum mesa_log_level { 407ec681f3Smrg MESA_LOG_ERROR, 417ec681f3Smrg MESA_LOG_WARN, 427ec681f3Smrg MESA_LOG_INFO, 437ec681f3Smrg MESA_LOG_DEBUG, 447ec681f3Smrg}; 457ec681f3Smrg 467ec681f3Smrgvoid PRINTFLIKE(3, 4) 477ec681f3Smrgmesa_log(enum mesa_log_level, const char *tag, const char *format, ...); 487ec681f3Smrg 497ec681f3Smrgvoid 507ec681f3Smrgmesa_log_v(enum mesa_log_level, const char *tag, const char *format, 517ec681f3Smrg va_list va); 527ec681f3Smrg 537ec681f3Smrg#define mesa_loge(fmt, ...) mesa_log(MESA_LOG_ERROR, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__) 547ec681f3Smrg#define mesa_logw(fmt, ...) mesa_log(MESA_LOG_WARN, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__) 557ec681f3Smrg#define mesa_logi(fmt, ...) mesa_log(MESA_LOG_INFO, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__) 567ec681f3Smrg#ifdef DEBUG 577ec681f3Smrg#define mesa_logd(fmt, ...) mesa_log(MESA_LOG_DEBUG, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__) 587ec681f3Smrg#else 597ec681f3Smrg#define mesa_logd(fmt, ...) __mesa_log_use_args((fmt), ##__VA_ARGS__) 607ec681f3Smrg#endif 617ec681f3Smrg 627ec681f3Smrg#define mesa_loge_v(fmt, va) mesa_log_v(MESA_LOG_ERROR, (MESA_LOG_TAG), (fmt), (va)) 637ec681f3Smrg#define mesa_logw_v(fmt, va) mesa_log_v(MESA_LOG_WARN, (MESA_LOG_TAG), (fmt), (va)) 647ec681f3Smrg#define mesa_logi_v(fmt, va) mesa_log_v(MESA_LOG_INFO, (MESA_LOG_TAG), (fmt), (va)) 657ec681f3Smrg#ifdef DEBUG 667ec681f3Smrg#define mesa_logd_v(fmt, va) mesa_log_v(MESA_LOG_DEBUG, (MESA_LOG_TAG), (fmt), (va)) 677ec681f3Smrg#else 687ec681f3Smrg#define mesa_logd_v(fmt, va) __mesa_log_use_args((fmt), (va)) 697ec681f3Smrg#endif 707ec681f3Smrg 717ec681f3Smrgstruct log_stream { 727ec681f3Smrg char *msg; 737ec681f3Smrg const char *tag; 747ec681f3Smrg size_t pos; 757ec681f3Smrg enum mesa_log_level level; 767ec681f3Smrg}; 777ec681f3Smrg 787ec681f3Smrgstruct log_stream *_mesa_log_stream_create(enum mesa_log_level level, char *tag); 797ec681f3Smrg#define mesa_log_streame() _mesa_log_stream_create(MESA_LOG_ERROR, (MESA_LOG_TAG)) 807ec681f3Smrg#define mesa_log_streamw() _mesa_log_stream_create(MESA_LOG_WARN, (MESA_LOG_TAG)) 817ec681f3Smrg#define mesa_log_streami() _mesa_log_stream_create(MESA_LOG_INFO, (MESA_LOG_TAG)) 827ec681f3Smrgvoid mesa_log_stream_destroy(struct log_stream *stream); 837ec681f3Smrgvoid mesa_log_stream_printf(struct log_stream *stream, const char *format, ...); 847ec681f3Smrg 857ec681f3Smrgvoid _mesa_log_multiline(enum mesa_log_level level, const char *tag, const char *lines); 867ec681f3Smrg#define mesa_log_multiline(level, lines) _mesa_log_multiline(level, (MESA_LOG_TAG), lines) 877ec681f3Smrg 887ec681f3Smrg#ifndef DEBUG 897ec681f3Smrg/* Suppres -Wunused */ 907ec681f3Smrgstatic inline void PRINTFLIKE(1, 2) 917ec681f3Smrg__mesa_log_use_args(UNUSED const char *format, ...) { } 927ec681f3Smrg#endif 937ec681f3Smrg 947ec681f3Smrg#ifdef __cplusplus 957ec681f3Smrg} 967ec681f3Smrg#endif 977ec681f3Smrg 987ec681f3Smrg#endif /* MESA_LOG_H */ 99