• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 #ifndef CTSAUDIO_LOG_H
18 #define CTSAUDIO_LOG_H
19 
20 #include <stdio.h>
21 #include <iostream>
22 #include <fstream>
23 
24 #include "FileUtil.h"
25 
26 class Log: public FileUtil {
27 public:
28     enum LogLevel {
29         ELogV = 0,
30         ELogD = 1,
31         ELogI = 2,
32         ELogW = 3,
33         ELogE = 4
34     };
35 
36     static Log* Instance(const char* dirName = NULL);
37     static void Finalize();
38 
39 
40     void printf(LogLevel level, const char* fmt, ...);
41     void setLogLevel(LogLevel level);
getLogLevel()42     LogLevel getLogLevel() {
43         return mLogLevel;
44     };
45 private:
46     Log();
47     virtual ~Log();
48     virtual bool init(const char* dirName);
49 
50 private:
51     static Log* mInstance;
52     LogLevel mLogLevel;
53 };
54 
55 #define LOGE(x...) do { Log::Instance()->printf(Log::ELogE, x); \
56     Log::Instance()->printf(Log::ELogE, "  file %s line %d", __FILE__, __LINE__); } while(0)
57 #define LOGW(x...) do { Log::Instance()->printf(Log::ELogW, x); } while(0)
58 #define LOGI(x...) do { Log::Instance()->printf(Log::ELogI, x); } while(0)
59 #define LOGD(x...) do { Log::Instance()->printf(Log::ELogD, x); } while(0)
60 #define LOGV(x...) do { Log::Instance()->printf(Log::ELogV, x); } while(0)
61 
62 #define MSG(x...) do { Log::Instance()->printf(Log::ELogE, x); } while(0)
63 
64 #define ASSERT(cond) if(!(cond)) {  Log::Instance()->printf(Log::ELogE, \
65         "assertion failed %s %d", __FILE__, __LINE__); \
66     Log::Finalize(); \
67     abort(); };
68 
69 #endif // CTSAUDIO_LOG_H
70