OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
file.c
Go to the documentation of this file.
1 #include "olog.h"
2 #include "olog/file.h"
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 
7 static int olog_backend_file_print(olog *olog, olog_backend *backend, uint8_t severity, va_list args) {
8  const char* format = va_arg(args, const char*);
9  int ret = vfprintf((FILE*) backend->data, format, args);
10  return ret < 0 ? OLOG_EXPLODED : 0;
11 }
12 
13 static int olog_backend_file_destroy(olog *olog, olog_backend *backend) {
14  if (backend->data) {
15  fclose(backend->data);
16  }
17  return 0;
18 }
19 static int olog_backend_has_error(olog *olog, olog_backend *backend) {
20  return backend->data == NULL;
21 }
22 static int olog_backend_print_error(olog *olog, olog_backend *backend, FILE* stream) {
23  if (backend->data == NULL) {
24  fprintf(stream, "Couldn't open file handle\n");
25  return 1;
26  }
27  return 0;
28 }
29 
30 olog_backend olog_backend_file_mode(const char *filename, const char *mode, int8_t min_log_level, int8_t max_log_level) {
31  FILE *stream = fopen(filename, mode);
32  olog_backend ret = {
33  .min_log_level = min_log_level,
34  .max_log_level = max_log_level,
35  .data = stream,
36  .print_callback = olog_backend_file_print,
37  .destroy_callback = olog_backend_file_destroy,
38  .has_error_callback = olog_backend_has_error,
39  .print_error_callback = olog_backend_print_error
40  };
41  return ret;
42 }
43 olog_backend olog_backend_file(const char *filename, int8_t min_log_level, int8_t max_log_level) {
44  return olog_backend_file_mode(filename, "w", min_log_level, max_log_level);
45 }
olog_backend olog_backend_file_mode(const char *filename, const char *mode, int8_t min_log_level, int8_t max_log_level)
Definition: file.c:30
#define NULL
Definition: decode_rs.h:63
olog_backend olog_backend_file(const char *filename, int8_t min_log_level, int8_t max_log_level)
Definition: file.c:43
README for MOD_PR02AQUA(AQUA) Version to set to For disabling creating and output data sets when in night mode
Definition: README.txt:96
int8_t min_log_level
Minimum log level to receive.
Definition: olog.h:66
A simple logger, capable of dispatching log events to multiple end points.
Definition: olog.c:11
char filename[FILENAME_MAX]
Definition: atrem_corl1.h:122
void * data
Storage for backend use.
Definition: olog.h:84
#define OLOG_EXPLODED
Definition: olog.h:53
format
Definition: mapgen.py:185