File size: 1,674 Bytes
90f0b29 |
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 |
/*
* Copyright (c) 2019-2024 Axera Semiconductor Co., Ltd. All Rights Reserved.
*
* This source file is the property of Axera Semiconductor Co., Ltd. and
* may not be copied or distributed in any isomorphic form without the prior
* written consent of Axera Semiconductor Co., Ltd.
*
* Author: wanglusheng@axera-tech.com
*/
#pragma once
#include <cstdarg>
#include <cstdio>
namespace utilities {
class log
{
public:
enum class type {
debug = 0,
info = 1,
warn = 2,
error = 3,
};
log() = default;
explicit log(const type& mode) : type_(mode) {}
~log() = default;
void print(const type& mode, const char *fmt, ...) const {
if (mode >= this->type_) {
switch (mode) {
case type::debug:
::fprintf(stdout, "[DEBUG] ");
break;
case type::info:
::fprintf(stdout, "[INFO] ");
break;
case type::warn:
::fprintf(stdout, "[WARNING] ");
break;
case type::error:
::fprintf(stdout, "[ERROR] ");
break;
}
::va_list args;
va_start(args, fmt);
::vprintf( fmt, args);
va_end(args);
}
::fflush(stdout);
}
void set_level(const type& mode) {
this->type_ = mode;
}
private:
type type_ = type::warn;
};
static log glog;
}
|