Morse Micro IoT SDK  2.9.7
log.h
1/*
2 * Copyright 2023 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#pragma once
8
9#include <stdarg.h>
10#include <stdint.h>
11#include <stdlib.h>
12
13#include "mmhal.h"
14#include "mmosal.h"
15
16#define ANSI_ESC_SGR(_n) "\033[" _n "m"
17#define ANSI_ESC_RESET ANSI_ESC_SGR("0")
18#define ANSI_ESC_BOLD ANSI_ESC_SGR("1")
19#define ANSI_ESC_FAINT ANSI_ESC_SGR("2")
20#define ANSI_ESC_RED ANSI_ESC_SGR("31")
21#define ANSI_ESC_GREEN ANSI_ESC_SGR("32")
22#define ANSI_ESC_YELLOW ANSI_ESC_SGR("33")
23#define ANSI_ESC_BLUE ANSI_ESC_SGR("34")
24#define ANSI_ESC_GRAY ANSI_ESC_SGR("90")
25
26#if LOG_COLOR_ENABLED != 0
27
28#define F_BOLD(_str) ANSI_ESC_BOLD _str ANSI_ESC_RESET
29#define F_FAINT(_str) ANSI_ESC_FAINT _str ANSI_ESC_RESET
30#define F_RED(_str) ANSI_ESC_RED _str ANSI_ESC_RESET
31#define F_BLUE(_str) ANSI_ESC_BLUE _str ANSI_ESC_RESET
32#define F_YELLOW(_str) ANSI_ESC_YELLOW _str ANSI_ESC_RESET
33#define F_GRAY(_str) ANSI_ESC_GRAY _str ANSI_ESC_RESET
34#define F_GREEN(_str) ANSI_ESC_GREEN _str ANSI_ESC_RESET
35#else
36#define F_BOLD(_str) _str
37#define F_FAINT(_str) _str
38#define F_RED(_str) _str
39#define F_BLUE(_str) _str
40#define F_YELLOW(_str) _str
41#define F_GRAY(_str) _str
42#define F_GREEN(_str) _str
43#endif
44
45#ifndef VSNPRINTF
46#define VSNPRINTF vsnprintf
47#endif
48
49static inline void log_printf(const char *fstr, ...)
50{
51 va_list arg;
52 va_start(arg, fstr);
53 char buf[128];
54 int len = VSNPRINTF(buf, sizeof(buf), fstr, arg);
55 MMOSAL_ASSERT(len >= 0);
56 va_end(arg);
57 mmhal_log_write((const uint8_t *)buf, len);
58}
59
60#define LOG_PRINTF(...) log_printf(__VA_ARGS__)
61#define LOG_WRITE(_str) mmhal_log_write((const uint8_t *)_str, strlen(_str))
62#define LOG_FLUSH() mmhal_log_flush()
63
64#ifndef STRINGIFY
65#define STRINGIFY(x) #x
66#endif
void mmhal_log_write(const uint8_t *data, size_t len)
Write to the debug log.
#define MMOSAL_ASSERT(expr)
Assert that the given expression evaluates to true and abort execution if not.
Definition: mmosal.h:927
char buf[1408]
Statically allocated buffer for HTTP GET request, just under 1 packet size.
Definition: sslclient.c:177