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