xref: /OK3568_Linux_fs/external/recovery/update_engine/log.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 // Copyright 2013 Google Inc. All Rights Reserved.
2 //
3 // Log - implemented using the standard Android logging mechanism
4 
5 /*
6  * Qutoing from system/core/include/log/log.h:
7  * Normally we strip ALOGV (VERBOSE messages) from release builds.
8  * You can modify this (for example with "#define LOG_NDEBUG 0"
9  * at the top of your source file) to change that behavior.
10  */
11 #include "log.h"
12 #include <stdio.h>
13 #include <stdarg.h>
14 
15 #define LOG_BUF_SIZE 1024
16 static int LOG_LEVEL = LOG_DEBUG;
17 
18 
InitLogging(LogPriority level)19 void InitLogging(LogPriority level)
20 {
21     if (level > 0)
22         LOG_LEVEL = level;
23 }
24 
Log(const char * file,int line,LogPriority level,const char * fmt,...)25 void Log(const char* file, int line, LogPriority level, const char* fmt, ...)
26 {
27     if (level > LOG_LEVEL) {
28         return;
29     }
30 
31     va_list ap;
32     char buf[LOG_BUF_SIZE];
33     va_start(ap, fmt);
34     vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
35     va_end(ap);
36 
37     switch (level) {
38     case LOG_ERROR:
39         printf("LOG_ERROR: %s", buf);
40         break;
41     case LOG_WARN:
42         printf("LOG_WARN: %s", buf);
43         break;
44     case LOG_INFO:
45         printf("LOG_INFO: %s", buf);
46         break;
47     case LOG_DEBUG:
48         printf("LOG_DEBUG: %s", buf);
49         break;
50     default :
51         break;
52     }
53 }
54