-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathlogging.h
More file actions
67 lines (54 loc) · 1.97 KB
/
Copy pathlogging.h
File metadata and controls
67 lines (54 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <glog/logging.h>
#include <stdexcept>
#include <string_view>
#include <version>
// CUDA interferes with <source_location> header
// https://forums.developer.nvidia.com/t/c-20s-source-location-compilation-error-when-using-nvcc-12-1/258026
#if defined SPDL_USE_CUDA && __has_include(<experimental/source_location>)
#include <experimental/source_location>
#elif defined __cpp_lib_source_location
#include <source_location>
#elif __has_include(<experimental/source_location>)
#include <experimental/source_location>
#else
#error \
"Neither <source_location> or <experimental/source_location> is available."
#endif
namespace spdl::common {
#if defined SPDL_USE_CUDA && __has_include(<experimental/source_location>)
using std::experimental::source_location;
#elif defined __cpp_lib_source_location
using std::source_location;
#else
using std::experimental::source_location;
#endif
std::string get_err_str(
const std::string_view msg,
const source_location& location);
std::string get_internal_err_str(
const std::string_view msg,
const source_location& location);
/// Exception thrown when unexpected internal error occurs.
class InternalError : public std::logic_error {
using std::logic_error::logic_error;
};
} // namespace spdl::common
#define SPDL_FAIL(msg) \
throw std::runtime_error( \
spdl::common::get_err_str( \
msg, spdl::common::source_location::current()))
#define SPDL_FAIL_INTERNAL(msg) \
throw spdl::common::InternalError( \
spdl::common::get_internal_err_str( \
msg, spdl::common::source_location::current()))
#define SPDL_WARN(msg) \
LOG(WARNING) << (spdl::common::get_err_str( \
msg, spdl::common::source_location::current()))