/*
 * Copyright (c) 2020-2022, NVIDIA CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <cugraph-ops/utils/string_utils.hpp>

#include <iostream>

namespace cugraph::ops::gnn::utils {

static constexpr int LEVEL_FATAL = 0;
static constexpr int LEVEL_ERROR = 10;
static constexpr int LEVEL_WARN  = 100;
static constexpr int LEVEL_INFO  = 1000;
static constexpr int LEVEL_TIMER = 10000;
static constexpr int LEVEL_DEBUG = 100000;
static constexpr int LEVEL_TRACE = 1000000;

int& get_log_level();

void set_log_level(int lev);

bool will_log_for(int lev);

#define CUGRAPH_OPS_LOG(lev, fmt, ...)                                                 \
  do {                                                                                 \
    if (cugraph::ops::gnn::utils::will_log_for(lev))                                   \
      std::cout << cugraph::ops::gnn::utils::format(fmt, ##__VA_ARGS__) << std::flush; \
  } while (0)

#define CUGRAPH_OPS_FATAL(fmt, ...) \
  CUGRAPH_OPS_LOG(cugraph::ops::gnn::utils::LEVEL_FATAL, fmt, ##__VA_ARGS__)
#define CUGRAPH_OPS_ERROR(fmt, ...) \
  CUGRAPH_OPS_LOG(cugraph::ops::gnn::utils::LEVEL_ERROR, fmt, ##__VA_ARGS__)
#define CUGRAPH_OPS_WARN(fmt, ...) \
  CUGRAPH_OPS_LOG(cugraph::ops::gnn::utils::LEVEL_WARN, fmt, ##__VA_ARGS__)
#define CUGRAPH_OPS_INFO(fmt, ...) \
  CUGRAPH_OPS_LOG(cugraph::ops::gnn::utils::LEVEL_INFO, fmt, ##__VA_ARGS__)
#define CUGRAPH_OPS_DEBUG(fmt, ...) \
  CUGRAPH_OPS_LOG(cugraph::ops::gnn::utils::LEVEL_DEBUG, fmt, ##__VA_ARGS__)
#define CUGRAPH_OPS_TRACE(fmt, ...) \
  CUGRAPH_OPS_LOG(cugraph::ops::gnn::utils::LEVEL_TRACE, fmt, ##__VA_ARGS__)

}  // namespace cugraph::ops::gnn::utils
