klog.h
Go to the documentation of this file.
1 /*
2  * KubOS Core Flight Services
3  * Copyright (C) 2015 Kubos Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
33 #ifndef KLOG_H
34 #define KLOG_H
35 
36 #include <stdint.h>
37 #include <stdio.h>
38 #include <csp/csp_types.h>
39 
40 //#define MODULE_LOG
41 #include "kubos-core/k_log.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #ifndef KLOG_MAX_LINE
48 #define KLOG_MAX_LINE 255
49 #endif
50 
51 #define KLOG(level, logger, ...) klog_write(level, logger, __VA_ARGS__)
52 #define KLOG_ERR(logger, ...) KLOG(LOG_ERROR, logger, __VA_ARGS__)
53 #define KLOG_WARN(logger, ...) KLOG(LOG_WARNING, logger, __VA_ARGS__)
54 #define KLOG_INFO(logger, ...) KLOG(LOG_INFO, logger, __VA_ARGS__)
55 #define KLOG_DEBUG(logger, ...) KLOG(LOG_DEBUG, logger, __VA_ARGS__)
56 
57 #define KLOG_SUFFIX_LEN 4
58 #define KLOG_PATH_LEN 255
59 #define KLOG_MAX_PATH (KLOG_PATH_LEN - KLOG_SUFFIX_LEN - 1)
60 
61 #define KLOG_PART_SIZE_DEFAULT (1024 * 512)
62 #define KLOG_MAX_PARTS_DEFAULT 4
63 
64 extern uint8_t klog_console_level;
65 extern uint8_t klog_file_level;
66 extern bool klog_file_logging;
67 
68 int klog_init_file(char *file_path, uint8_t file_path_len,
69  uint32_t part_size, uint8_t max_parts);
70 
71 void klog_console(unsigned level, const char *logger, const char *format, ...);
72 void klog_file(unsigned level, const char *logger, const char *format, ...);
73 void klog_cleanup(void);
74 
75 #define klog_write(level, logger, ...) do { \
76  if (level <= klog_console_level) { \
77  klog_console(level, logger, __VA_ARGS__); \
78  } \
79  if (level <= klog_file_level && klog_file_logging) { \
80  klog_file(level, logger, __VA_ARGS__); \
81  } \
82 } while (0)
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 
88 #endif
89 
90 /* @} */
System logging header.
void klog_cleanup(void)
void klog_console(unsigned level, const char *logger, const char *format,...)
bool klog_file_logging
void klog_file(unsigned level, const char *logger, const char *format,...)
uint8_t klog_file_level
uint8_t klog_console_level
int klog_init_file(char *file_path, uint8_t file_path_len, uint32_t part_size, uint8_t max_parts)