OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
olog-main.c
Go to the documentation of this file.
1 #include <olog.h>
2 #include <olog/loader.h>
3 
4 #include <olog/buffer.h>
5 #include <olog/file.h>
6 #include <olog/stream.h>
7 #include <olog/streamf.h>
8 
9 #include <phash.h>
10 
11 #include <stdio.h>
12 #include <string.h>
13 
14 static unsigned message_count = 0;
16  olog_streamf *backend_data = (olog_streamf*) backend->data;
17  int ret = fprintf(backend_data->stream, "%u", ++message_count);
18  return ret < 0 ? OLOG_EXPLODED : 0;
19 }
21  olog_streamf *backend_data = (olog_streamf*) backend->data;
22  int ret = fprintf(backend_data->stream, "%3u", ++message_count);
23  return ret < 0 ? OLOG_EXPLODED : 0;
24 }
25 
26 int main(int argc, char *argv[]) {
27  if (0) {
28  phash *p1 = phash_create(0);
29  phash_set(p1, "host", "host1");
30 
31  void *indexed_pointers[1];
32  indexed_pointers[0] = get_message_count;
33 
34  olog_streamf_arguments streamf_args = {
35  .stream = stdout,
36  .named_pointers = p1,
37  .persistent_hash = true,
38  .indexed_pointers = indexed_pointers,
39  //.persistent_indexes = true,
40  .format = "[%[0]A] %t [%u] %%%n%n | [%l] | [%{host}s] | %s"
41  };
42  olog_backend streamf = olog_backend_streamf(&streamf_args, 2, 7);
43  olog_backend backends[] = {
44  streamf,
45  { 0 }
46  };
47  olog *logger = olog_create(backends, stderr);
48  if (logger == NULL) {
49  return 1;
50  }
51 
52  olog_err(logger, "Test string 1\n");
53  phash_set(p1, "host", "host2");
54  indexed_pointers[0] = get_message_count2;
55  olog_err(logger, "Test string 2\n");
56 
59  }
60 
61  if (0) {
62  olog_streamf_arguments streamf_args = {
63  .stream = stderr,
64  .format = "%t [%u] %s"
65  };
66  olog_backend backends[] = {
67  olog_backend_streamf(&streamf_args, 1, 3),
69  { 0 }
70  };
71  olog *logger = olog_create(backends, stderr);
72  if (logger == NULL) {
73  return 1;
74  }
75 
76  olog_err(logger, "Test string 1\n");
77  olog_err(logger, "Test string 2\n");
79  }
80 
81  if (0) {
82  olog_backend backends[] = {
85  //olog_backend_file("/accounts/jlefler/test.out", 0, 7),
86  { 0 }
87  };
88  olog *logger = olog_create(backends, stderr);
89  if (logger == NULL) {
90  return 1;
91  }
92 
93  olog_info(logger, "Test string: %s\n", "qwer");
94  olog_err(logger, "Test string 3: %s\n", "asdf");
96  }
97 
98  if (0) {
99  olog_backend buffer = olog_backend_buffer(32, 0, 7);
100  olog_backend backends[] = {
101  buffer,
102  { 0 }
103  };
104  olog *logger = olog_create(backends, stderr);
105  if (logger == NULL) {
106  return 1;
107  }
108 
109  for (int i = 0; i < 150; i++) {
110 // if (olog_info(logger, "Test string: %d\n", i)){
111 // break;
112 // }
113  if (olog_info(logger, "%d", i % 10)) {
114  break;
115  }
116  }
117 
118  printf("%s\n", ((olog_buffer*) buffer.data)->buffer_start);
120  }
121 
122  if (0) {
123  olog_info(NULL, "Test string 1\n");
124  olog_crit(NULL, "Test string 2\n");
125  olog_print_verbose(NULL, OLOG_INFO, "Test string %d\n", 15);
126  olog_crit(NULL, "%s, %d\n", __FILE__, __LINE__);
128 // olog_destroy_default();
129  }
130 
131  if (1) {
132  olog *log = olog_load_default();
133  if (olog_global_log == log) {
134  printf("Same\n");
135  } else {
136  printf("not same\n");
137  }
138  }
139 
140  return 0;
141 }
142 
int olog_crit(olog *olog,...)
#define OLOG_INFO
Definition: olog.h:43
#define NULL
Definition: decode_rs.h:63
int get_message_count(olog *olog, olog_backend *backend)
Definition: olog-main.c:15
olog * olog_create(olog_backend *backends, FILE *stream)
Definition: olog.c:15
int olog_info(olog *olog,...)
olog_backend olog_backend_stream(FILE *stream, int8_t min_log_level, int8_t max_log_level)
Definition: stream.c:13
#define olog_print_verbose(olog, level,...)
Definition: olog.h:108
int get_message_count2(olog *olog, olog_backend *backend)
Definition: olog-main.c:20
A simple logger, capable of dispatching log events to multiple end points.
A simple dictionary library for storing pointers.
phash * phash_create(uint32_t options)
Initialize a phash object.
Definition: phash.c:107
int olog_err(olog *olog,...)
olog_backend olog_backend_streamf(olog_streamf_arguments *arguments, int8_t min_log_level, int8_t max_log_level)
Definition: streamf.c:362
int main(int argc, char *argv[])
Definition: olog-main.c:26
olog * olog_load_default()
Definition: olog_loader.c:12
Definition: olog.c:11
olog_backend olog_backend_buffer(size_t initial_size, int8_t min_log_level, int8_t max_log_level)
Definition: buffer.c:76
Implementation-specific, generic type to store the phash object.
Definition: phash.c:40
FILE * stream
Definition: streamf.h:45
int phash_set(phash *h, const char *key, void *value)
Add or overwrite a pointer, associating it with the given key.
Definition: phash.c:224
olog * olog_global_log
Definition: olog_loader.c:8
void * data
Storage for backend use.
Definition: olog.h:84
#define OLOG_EXPLODED
Definition: olog.h:53
int phash_destroy(phash *h)
Destroy a phash object, free'ing the memory used.
Definition: phash.c:136
int i
Definition: decode_rs.h:71
void olog_destroy(olog *olog)
Definition: olog.c:60