Blame view

RIOT/pkg/openthread/contrib/platform_logging.c 2.12 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  /*
   * Copyright (C) 2017 Fundacion Inria Chile
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @{
   * @ingroup     net
   * @file
   * @brief       Implementation of OpenThread logging platform abstraction
   *
   * @author      Jose Ignacio Alamos <jialamos@uc.cl>
   * @}
   */
  
  #include <ctype.h>
  #include <inttypes.h>
  #include <stdarg.h>
  #include <stdio.h>
  #include <stdint.h>
  #include <string.h>
  #include <time.h>
  
  #include "openthread/platform/logging.h"
  
  /* adapted from OpenThread posix example:
   * See: https://github.com/openthread/openthread/blob/master/examples/platforms/posix/logging.c */
  void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
  {
      va_list args;
  
      switch (aLogLevel) {
          case kLogLevelNone:
              fprintf(stderr, "NONE ");
              break;
  
          case kLogLevelCrit:
              fprintf(stderr, "CRIT ");
              break;
  
          case kLogLevelWarn:
              fprintf(stderr, "WARN ");
              break;
  
          case kLogLevelInfo:
              fprintf(stderr, "INFO ");
              break;
  
          case kLogLevelDebg:
              fprintf(stderr, "DEBG ");
              break;
      }
  
      switch (aLogRegion) {
          case kLogRegionApi:
              fprintf(stderr, "API  ");
              break;
  
          case kLogRegionMle:
              fprintf(stderr, "MLE  ");
              break;
  
          case kLogRegionArp:
              fprintf(stderr, "ARP  ");
              break;
  
          case kLogRegionNetData:
              fprintf(stderr, "NETD ");
              break;
  
          case kLogRegionIp6:
              fprintf(stderr, "IPV6 ");
              break;
  
          case kLogRegionIcmp:
              fprintf(stderr, "ICMP ");
              break;
  
          case kLogRegionMac:
              fprintf(stderr, "MAC  ");
              break;
  
          case kLogRegionMem:
              fprintf(stderr, "MEM  ");
              break;
          default:
              break;
      }
  
      va_start(args, aFormat);
      vfprintf(stderr, aFormat, args);
      fprintf(stderr, "\r");
      va_end(args);
  }