-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogga.h
More file actions
141 lines (119 loc) · 4.17 KB
/
Copy pathlogga.h
File metadata and controls
141 lines (119 loc) · 4.17 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* @file logga.h
* @brief this file implements a minimalistic logging interface
* for embedded or desktop apps
* @author Edwin Mwiti
*/
#ifndef LOGGA_H
#define LOGGA_H
#include "config.h"
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct Logga* Logga_Type_t; /* forward declare Logga structure */
typedef struct SystemTime* SystemTime_t; /* to hold the current system time -> will be passed in by the user*/
#define MAX_FILE_SIZE 2097152
typedef enum _file_create_status_enum {
LOGGA_FILE_EXISTS = 0,
LOGGA_FAILED_TO_CREATE_LOG_FILE = 1,
LOGGA_FAILED_TO_CREATE_LOG_FOLDER = 2,
LOGGA_FAILED_TO_LOG_FILE = 3,
LOGGA_FAILED_TO_READ_FILE = 4,
LOGGA_FAILED_TO_APPEND_FILE = 5,
LOGGA_FAILED_TO_OPEN_FILE = 6,
LOGGA_FILE_CREATE_OK = 7,
LOGGA_FOLDER_CREATE_OK = 8,
LOGGA_FAILED_TO_OPEN_SPIFFS = 9,
LOGGA_INVALID_FILENAME = 10,
LOGGA_FILE_DELETE_OK = 11,
LOGGA_FAILED_TO_DELETE_FILE = 12,
LOGGA_FILE_CLEARED_OK = 13,
LOGGA_FILE_DUMP_OK = 14
} FILE_STATUS;
class Logga {
private:
const char* _f_name;
const char* _dir_name;
uint32_t _f_size;
const char* _ntp_server;
void _get_time(void);
void _init_spiffs();
public:
Logga(const char* f_name, const char* dir_name);
FILE_STATUS logga_init();
uint8_t logga_write(char* d);
FILE_STATUS logga_dump(const char* fname);
uint32_t logga_get_file_size();
FILE_STATUS logga_delete(const char* f_name);
FILE_STATUS logga_clear_file(const char* f_name);
};
/**
* Function definition
*/
/**
* @brief allocate teh object we are going to be using for logging
* @return
*
*/
// Logga_Type_t create_logga();
// /**
// * @brief init_logga initialize a logging object
// * @param _logga_inst instance of the logger object being used
// * @param fname filename to log to
// * @param f_size size of the file to create
// */
// uint8_t init_logga(Logga_Type_t _logga_inst, const char* fname);
// const char* get_ntp_time(Logga_Type_t obj);
// /**
// * @brief Initialize SPIFFS file system for ESP32
// * @param _logga_inst
// * @return 1 if successful
// *
// */
// uint8_t init_SPIFFS(Logga_Type_t _logga_inst);
// /**
// * @brief check the size of file to create
// * if the size is greater than the allowed file size, return the default max allowed file size
// * @param sz size passed by the caller
// */
// uint32_t check_file_size(Logga_Type_t _logga_inst, uint32_t sz);
// /**
// * @brief check the number of files already created in the passed directory
// * If the number of files is greater than the allowed number of files,
// * delete the oldest file to create space -> majorly for embedded
// * todo: add embedded usage check
// * @param dir_name directory to check
// */
// void check_num_files(Logga_Type_t _logga_inst, const char* dir_name);
// /**
// * @brief writes the log to filename passed during creation
// * @param t_stamp
// * @param TAG
// * @param LEVEL
// * @param MSG
// */
// void write_log(Logga_Type_t _logga_inst, const char* t_stamp, const char* TAG, const char* LEVEL, const char* MSG);
// /**
// * @brief log data to the given file
// * This function is for use in embedded controller
// * @param _logga_inst
// * @param t_stamp
// * @param TAG
// * @param LEVEL
// * @param MSG
// */
// void log_message(Logga_Type_t _logga_inst, unsigned long t_stamp, const char* TAG, const char* LEVEL, const char* MSG);
// char* log_get_filepath(Logga_Type_t obj);
// void log_trace(Logga_Type_t obj, const char* tag, const char* msg);
// void log_debug(const char* tag, const char* msg);
// void log_info(const char* tag, const char* msg);
// void log_warn(const char* tag, const char* msg);
// void log_error(const char* tag, const char* msg);
// void log_fatal(const char* tag, const char* msg);
#ifdef __cplusplus
}
#endif
#endif // END LOGGA_H