Arduino FDK AAC Encoder and Decoder Library
All Classes Namespaces Functions Enumerations Enumerator Pages
fdk_log.h
1 #pragma once
2 
3 // User Settings: Activate/Deactivate logging
4 #ifndef FDK_LOGGING_ACTIVE
5 #define FDK_LOGGING_ACTIVE true
6 #endif
7 
8 #ifndef FDK_LOG_LEVEL
9 #define FDK_LOG_LEVEL FDKWarning
10 #endif
11 
12 // Logging Implementation
13 #if FDK_LOGGING_ACTIVE == true
14 
15 #ifndef ARDUINO
16 #include <stdio.h>
17 #endif
18 
19 static char log_buffer[512];
20 enum LogLevelFDK {FDKDebug, FDKInfo, FDKWarning, FDKError};
21 static LogLevelFDK minLogLevelFDK = FDKWarning;
22 
23 static const char* levelName(LogLevelFDK level) {
24  switch(level){
25  case FDKDebug:
26  return "D";
27  case FDKInfo:
28  return "I";
29  case FDKWarning:
30  return "W";
31  case FDKError:
32  return "E";
33  }
34  return "";
35 }
36 
37 static void printLogFDK(const char*msg){
38 #ifdef ARDUINO
39  Serial.print(msg);
40 #else
41  printf("%s",msg);
42 #endif
43 }
44 
45 static void printLogFDK(const char* file, int line, LogLevelFDK current_level) {
46  const char* file_name = strrchr(file, '/') ? strrchr(file, '/') + 1 : file;
47  const char* level_code = levelName(current_level);
48  printLogFDK("[");
49  printLogFDK(level_code);
50  printLogFDK("] ");
51  printLogFDK(file_name);
52  printLogFDK(" : ");
53  char line_str[20];
54  snprintf(line_str,20,"%d",line);
55  printLogFDK(line_str);
56  printLogFDK(" - ");
57  printLogFDK(log_buffer);
58  printLogFDK("\n");
59 }
60 
61 // We print the log based on the log level
62 #define LOG_FDK(level,...) { if(level>=minLogLevelFDK) { snprintf(log_buffer,512, __VA_ARGS__); printLogFDK(__FILE__,__LINE__, level); } }
63 #else
64 // Remove all log statments from the code
65 #define LOG_FDK(FDKDebug, ...)
66 #endif