1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "oc_logger.h"
22 #include "targets/oc_console_logger.h"
30 } oc_console_logger_ctx;
32 oc_log_ctx_t *oc_make_console_logger()
34 return oc_log_make_ctx(
37 oc_console_logger_init,
38 oc_console_logger_destroy,
39 oc_console_logger_flush,
40 oc_console_logger_set_level,
41 oc_console_logger_write,
42 oc_console_logger_set_module
46 int oc_console_logger_init(oc_log_ctx_t *ctx, void *world)
49 oc_console_logger_ctx *my_ctx;
51 my_ctx = (oc_console_logger_ctx *)malloc(sizeof(oc_console_logger_ctx));
58 ctx->ctx = (void *)my_ctx;
63 void oc_console_logger_destroy(oc_log_ctx_t *ctx)
65 oc_console_logger_ctx *lctx = (oc_console_logger_ctx *)ctx->ctx;
72 void oc_console_logger_flush(oc_log_ctx_t *ctx)
74 oc_console_logger_ctx *lctx = (oc_console_logger_ctx *)ctx->ctx;
79 void oc_console_logger_set_level(oc_log_ctx_t *ctx, const int level)
83 /* We don't have any special thing we need to do when a log level changes. */
87 size_t oc_console_logger_write(oc_log_ctx_t *ctx, const int level, const char *msg)
89 oc_console_logger_ctx *lctx = (oc_console_logger_ctx *)ctx->ctx;
91 /* A "real" implementation might want to replace the loglevel with a mnemonic: */
93 if(0 == ctx->module_name)
94 return 1 + fprintf(lctx->out, "%d: %s\n", level, msg);
96 return 1 + fprintf(lctx->out, "%d: [%s]: %s\n", level, ctx->module_name, msg);
99 int oc_console_logger_set_module(oc_log_ctx_t *ctx, const char *module_name)
103 /* We don't do anything special when the module name changes: */