| 142 | } |
| 143 | |
| 144 | static xlog_context* xlog_new_context(int bConsole) |
| 145 | { |
| 146 | int i=0; |
| 147 | xlog_context *ctx = (xlog_context*)malloc(sizeof(xlog_context)); |
| 148 | |
| 149 | if (ctx != NULL){ |
| 150 | for(i=0; i< RECEIVER_MAX_COUNT; i++){ |
| 151 | ctx->_receivers[i]._fn = NULL; |
| 152 | ctx->_receivers[i]._file = NULL; |
| 153 | ctx->_receivers[i]._enable = 0; |
| 154 | ctx->_receivers[i]._rev = NULL; |
| 155 | ctx->_receivers[i]._type = -1; |
| 156 | } |
| 157 | ctx->_count = 0; |
| 158 | ctx->_log_level = XLOG_LEVEL_INFO; |
| 159 | |
| 160 | if (bConsole){ |
| 161 | ctx->_receivers[0]._fn = print_to_console; |
| 162 | ctx->_receivers[0]._type = RECEIVER_TYPE_CONSOLE; |
| 163 | ctx->_receivers[0]._enable = 1; |
| 164 | ctx->_count = 1; |
| 165 | } |
| 166 | |
| 167 | pthread_mutex_init(&ctx->_mutext, NULL); |
| 168 | } |
| 169 | |
| 170 | return ctx; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * create a log context, the console is default log receiver |