Revert "Change build option - IP only"
[platform/upstream/iotivity.git] / resource / oc_logger / samples / linux / test_logging.c
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include "logger.h"
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26
27 #define TAG  ("MAIN")
28
29 static int customLogger = 0;
30
31 static void PrintUsage()
32 {
33     OC_LOG(INFO, TAG, "Usage : test_logging -c <0|1>");
34     OC_LOG(INFO, TAG, "-u <0|1> : 0 - default logging, 1 - custom console logging");
35 }
36
37 int main(int argc, char* argv[])
38 {
39     int opt;
40
41     while ((opt = getopt(argc, argv, "c:")) != -1)
42     {
43         switch(opt)
44         {
45             case 'c':
46                 customLogger = atoi(optarg);
47                 break;
48             default:
49                 PrintUsage();
50                 return -1;
51         }
52     }
53
54     if (customLogger == 0)
55     {
56         // Default logger
57         OC_LOG(DEBUG, TAG, "This is a DEBUG");
58         OC_LOG(INFO, TAG, "This is a INFO");
59         OC_LOG(WARNING, TAG, "This is a WARNING");
60         OC_LOG(ERROR, TAG, "This is a ERROR");
61         OC_LOG(FATAL, TAG, "This is a FATAL");
62     }
63     else
64     {
65         // Custom logger, in this case, the console logger
66         oc_log_ctx_t *log = oc_make_console_logger();
67
68         OC_LOG_CONFIG(log);
69
70         OC_LOG(DEBUG, TAG, "This is a DEBUG");
71         OC_LOG(INFO, TAG, "This is a INFO");
72         OC_LOG(WARNING, TAG, "This is a WARNING");
73         OC_LOG(ERROR, TAG, "This is a ERROR");
74         OC_LOG(FATAL, TAG, "This is a FATAL");
75         OC_LOG_SHUTDOWN();
76     }
77
78
79     return 0;
80 }