log.h 1.09 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
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
#ifndef LIGHTGBM_UTILS_LOG_H_
#define LIGHTGBM_UTILS_LOG_H_

#include <cstdio>
#include <cstdlib>
#include <cstdarg>
#include <cstring>

namespace LightGBM {

class Log {
public:

  inline static void Stderr(const char *format, ...) {
    va_list argptr;
    char fixed[512];
#ifdef _MSC_VER
    sprintf_s(fixed, "[LightGBM Error] %s \n", format);
#else
    sprintf(fixed, "[LightGBM Error] %s \n", format);
#endif
    va_start(argptr, format);
    vfprintf(stderr, fixed, argptr);
    va_end(argptr);
    fflush(stderr);
    std::exit(1);
  }

  inline static void Stdout(const char *format, ...) {
    va_list argptr;
    char fixed[512];
#ifdef _MSC_VER
    sprintf_s(fixed, "[LightGBM] %s\n", format);
#else
    sprintf(fixed, "[LightGBM] %s\n", format);
#endif
    va_start(argptr, format);
    vfprintf(stdout, fixed, argptr);
    va_end(argptr);
    fflush(stdout);
  }
};

#define CHECK(condition)                                   \
  if (!(condition)) Log::Stderr("Check failed: " #condition \
     " at %s, line %d .\n", __FILE__,  __LINE__);

}  // namespace LightGBM
Guolin Ke's avatar
Guolin Ke committed
49
#endif   // LightGBM_UTILS_LOG_H_