marsrs-react-native-xlog 0.1.0-alpha.2 → 0.1.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -8
  3. package/android/build.gradle.kts +1 -1
  4. package/android/src/main/kotlin/io/github/orangeboychen/marsrs/xlog/reactnative/XlogModule.kt +248 -43
  5. package/ios/Frameworks/marsrs-xlog.xcframework/Info.plist +83 -0
  6. package/ios/Frameworks/marsrs-xlog.xcframework/ios-arm64/Headers/mars_xlog.h +242 -0
  7. package/ios/Frameworks/marsrs-xlog.xcframework/ios-arm64/Headers/module.modulemap +4 -0
  8. package/ios/Frameworks/marsrs-xlog.xcframework/ios-arm64/libmars_ffi.a +0 -0
  9. package/ios/Frameworks/marsrs-xlog.xcframework/ios-arm64_x86_64-simulator/Headers/mars_xlog.h +242 -0
  10. package/ios/Frameworks/marsrs-xlog.xcframework/ios-arm64_x86_64-simulator/Headers/module.modulemap +4 -0
  11. package/ios/Frameworks/marsrs-xlog.xcframework/ios-arm64_x86_64-simulator/libmars_ffi.a +0 -0
  12. package/ios/Frameworks/marsrs-xlog.xcframework/watchos-arm64-simulator/Headers/mars_xlog.h +242 -0
  13. package/ios/Frameworks/marsrs-xlog.xcframework/watchos-arm64-simulator/Headers/module.modulemap +4 -0
  14. package/ios/Frameworks/marsrs-xlog.xcframework/watchos-arm64-simulator/libmars_ffi.a +0 -0
  15. package/ios/Frameworks/marsrs-xlog.xcframework/watchos-arm64_arm64_32/Headers/mars_xlog.h +242 -0
  16. package/ios/Frameworks/marsrs-xlog.xcframework/watchos-arm64_arm64_32/Headers/module.modulemap +4 -0
  17. package/ios/Frameworks/marsrs-xlog.xcframework/watchos-arm64_arm64_32/libmars_ffi.a +0 -0
  18. package/ios/Xlog.mm +2 -2
  19. package/ios/Xlog.swift +263 -37
  20. package/ios/include/mars_xlog.h +242 -0
  21. package/package.json +1 -1
  22. package/src/NativeXlog.ts +28 -3
  23. package/src/index.ts +143 -20
  24. package/android/.gradle/9.2.0/checksums/checksums.lock +0 -0
  25. package/android/.gradle/9.2.0/fileChanges/last-build.bin +0 -0
  26. package/android/.gradle/9.2.0/fileHashes/fileHashes.bin +0 -0
  27. package/android/.gradle/9.2.0/fileHashes/fileHashes.lock +0 -0
  28. package/android/.gradle/9.2.0/gc.properties +0 -0
  29. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  30. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  31. package/android/.gradle/vcs-1/gc.properties +0 -0
@@ -0,0 +1,242 @@
1
+ /* Tencent is pleased to support the open source community by making Mars available.
2
+ * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
3
+ *
4
+ * Licensed under the MIT License (the "License"); you may not use this file except in
5
+ * compliance with the License. You may obtain a copy of the License at
6
+ * http://opensource.org/licenses/MIT
7
+ *
8
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
9
+ * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10
+ * either express or implied. See the License for the specific language governing permissions and
11
+ * limitations under the License.
12
+ */
13
+
14
+ /*
15
+ * mars_xlog.h — C ABI of the Rust xlog implementation (`marsrs-ffi`).
16
+ *
17
+ * This header is the drop-in seam for the existing C++ / JNI / ObjC layers of
18
+ * Mars. It mirrors the C++ surface of
19
+ *
20
+ * mars/xlog/appender.h (mars::xlog::appender_open / flush / close ...)
21
+ * mars/xlog/xlogger_interface.h (mars::xlog::XloggerWrite / SetLevel ...)
22
+ * mars/comm/xlogger/xloggerbase.h (TLogLevel)
23
+ *
24
+ * and is the C equivalent of the JNI bridge in mars/xlog/jni/Java2C_Xlog.cc.
25
+ *
26
+ * The header is hand-written and checked in next to the crate so that a C/C++
27
+ * caller can include it without running cbindgen. It is kept in sync with
28
+ * `src/abi.rs` by `tests/header_sync.rs`.
29
+ *
30
+ * Threading: every symbol may be called from any thread. The setters and the
31
+ * instance lifecycle mutate shared state (exactly like the C++ globals) and
32
+ * should be called from one place during start-up / shut-down. What no symbol
33
+ * here does is install a process-wide appender: an app opens an instance with
34
+ * `mars_xlog_new_instance` and writes through the handle it answers. Handle
35
+ * `0` names no appender at all — it is what an open that failed answers, and
36
+ * every symbol asked of it is a no-op.
37
+ *
38
+ * Panics: no Rust panic ever crosses this boundary. Every entry point is
39
+ * wrapped in `catch_unwind`; a panic is reported as `MARS_XLOG_ERR_PANIC` (or
40
+ * silently swallowed for the `void` symbols).
41
+ */
42
+
43
+ #ifndef MARS_XLOG_H_
44
+ #define MARS_XLOG_H_
45
+
46
+ /* The symbols this header declares are the ones `#[no_mangle]` exports: plain
47
+ * C names, and a C++ translation unit that includes this and calls
48
+ * `mars_xlog_new_instance()` asks its linker for a mangled one that does not
49
+ * exist.
50
+ * `mars_stn.h` and `mars_sdt.h` carry the same guard, and `mars_xlog.hpp` —
51
+ * the C++ face of this seam — includes this one, so a C++ caller asks for the
52
+ * same names whichever of the two it takes. */
53
+ #ifdef __cplusplus
54
+ extern "C" {
55
+ #endif
56
+
57
+ /* --- enums ------------------------------------------------------------- */
58
+
59
+ /** Mirrors `mars::xlog::TAppenderMode` (appender.h). */
60
+ typedef enum { MarsAppenderAsync = 0, MarsAppenderSync = 1 } MarsAppenderMode;
61
+
62
+ /** Mirrors `mars::xlog::TCompressMode` (appender.h). */
63
+ typedef enum { MarsCompressZlib = 0, MarsCompressZstd = 1 } MarsCompressMode;
64
+
65
+ /** Mirrors `TLogLevel` (xloggerbase.h); `kLevelAll == kLevelVerbose == 0`. */
66
+ typedef enum {
67
+ MarsLevelVerbose = 0,
68
+ MarsLevelDebug = 1,
69
+ MarsLevelInfo = 2,
70
+ MarsLevelWarn = 3,
71
+ MarsLevelError = 4,
72
+ MarsLevelFatal = 5
73
+ } MarsLogLevel;
74
+
75
+ /** Additional level understood only by the filter: disables every record. */
76
+ #define MARS_LEVEL_NONE 6
77
+
78
+ /* --- return codes -------------------------------------------------------
79
+ *
80
+ * The five from `NULL_CONFIG` to `APPENDER` are the reasons an open may be
81
+ * refused, and no symbol hands them out: `mars_xlog_new_instance` answers the
82
+ * handle `0` for every one of them, there being no room in a handle for a
83
+ * negative code. They are here for the caller that wants to name the reason in
84
+ * its own diagnostic, not to switch on an answer.
85
+ */
86
+ #define MARS_XLOG_OK 0
87
+ #define MARS_XLOG_ERR_NULL_CONFIG (-1) /* `config` was NULL */
88
+ #define MARS_XLOG_ERR_BAD_MODE (-2) /* `mode` outside MarsAppenderMode */
89
+ #define MARS_XLOG_ERR_BAD_COMPRESS (-3) /* `compress_mode` outside MarsCompressMode */
90
+ #define MARS_XLOG_ERR_EMPTY_LOG_DIR (-4) /* `log_dir` was NULL or "" */
91
+ #define MARS_XLOG_ERR_APPENDER (-5) /* the Rust appender refused the config */
92
+ #define MARS_XLOG_ERR_NULL_OUT (-6) /* `out` was NULL */
93
+ #define MARS_XLOG_ERR_NO_SPACE (-7) /* output buffer too small (0 or < need) */
94
+ #define MARS_XLOG_ERR_NO_PATH (-8) /* no current log file is open */
95
+ #define MARS_XLOG_ERR_PANIC (-99) /* a Rust panic was caught at the boundary */
96
+
97
+ /* --- config ------------------------------------------------------------- */
98
+
99
+ /**
100
+ * Mirrors `mars::xlog::XLogConfig` (appender.h) with C strings instead of
101
+ * `std::string`. Every pointer must be NUL-terminated UTF-8 or NULL; NULL is
102
+ * treated as "empty" (see the field docs) except for `log_dir`, which is
103
+ * mandatory.
104
+ */
105
+ typedef struct {
106
+ int mode; /* MarsAppenderMode; default when unset: Async */
107
+ const char* log_dir; /* mandatory, directory is created if missing */
108
+ const char* name_prefix; /* used verbatim; no default; "" is refused */
109
+ const char* pub_key; /* NULL / "" => logs are written unencrypted */
110
+ int compress_mode; /* MarsCompressMode; default when unset: Zlib */
111
+ int compress_level; /* <= 0 => keep the appender default (6) */
112
+ const char* cache_dir; /* NULL / "" => the mmap cache lives in log_dir */
113
+ int cache_days; /* < 0 => 0; 0 => keep every file */
114
+ } MarsXLogConfig;
115
+
116
+ /* ---- logger instances (mars::xlog::NewXloggerInstance and friends) ----
117
+ *
118
+ * Each instance owns an appender: its own log directory, prefix, key, mode and
119
+ * cache file. A C caller that wants a logger opens one with
120
+ * mars_xlog_new_instance and holds the handle it answers.
121
+ *
122
+ * Every call that can be asked of an instance exists only in this spelling:
123
+ * the C++ has a free function for its process-wide appender and a
124
+ * handle-taking one beside it, and a second spelling of the same operation
125
+ * here would be two ways to say one thing. There is no process-wide appender
126
+ * to install, so there is no free-function spelling either — and handle `0`,
127
+ * which is what a failed open answers, names no appender: the level, the mode,
128
+ * the console, the two sizes and the drain asked of it do nothing, and the
129
+ * questions answer "no" or `MARS_XLOG_ERR_NO_PATH`.
130
+ */
131
+
132
+ /* --- writing ------------------------------------------------------------- */
133
+
134
+ /* Returns the instance handle, or 0 on a null/invalid config. */
135
+ long long mars_xlog_new_instance(const MarsXLogConfig* config, int level);
136
+
137
+ /* The handle registered for name_prefix, or 0 when there is none. */
138
+ long long mars_xlog_get_instance(const char* name_prefix);
139
+
140
+ /* Releases the instance and closes its appender. Prefer the handle-aware
141
+ * mars_xlog_release_instance_of() when the caller holds an instance handle. */
142
+ void mars_xlog_release_instance(const char* name_prefix);
143
+
144
+ /* The same, and only while name_prefix is still registered under `instance`.
145
+ *
146
+ * Releasing takes the prefix and not the handle, so asking
147
+ * mars_xlog_get_instance and then calling mars_xlog_release_instance is two
148
+ * answers and not one: an open of the same prefix that lands between the two is
149
+ * handed a handle of its own, and the release closes that one. This is the
150
+ * question and the release in one call, which is also what makes a second
151
+ * close of a prefix a no-op however many callers hold its handle. */
152
+ void mars_xlog_release_instance_of(const char* name_prefix, long long instance);
153
+
154
+ /* Writes through an instance; honours the instance's level. */
155
+ void mars_xlog_write_instance(long long instance,
156
+ int level,
157
+ const char* tag,
158
+ const char* filename,
159
+ const char* func_name,
160
+ int line,
161
+ const char* log);
162
+
163
+ /* 1 when the instance would write this level, 0 otherwise. */
164
+ int mars_xlog_is_enabled_for(long long instance, int level);
165
+
166
+ /* The instance's level, or -1 for an unknown handle. */
167
+ int mars_xlog_get_level(long long instance);
168
+
169
+ /* SetLevel for an instance: the level `mars_xlog_get_level` and
170
+ * `mars_xlog_is_enabled_for` answer, and the one a write through the same
171
+ * handle asks. A no-op for handle `0`, which is no instance at all. */
172
+ void mars_xlog_set_level_instance(long long instance, int level);
173
+
174
+ /* appender_setmode / SetAppenderMode for an instance. */
175
+ void mars_xlog_set_mode_instance(long long instance, int mode);
176
+
177
+ /* Drains an instance, requested: the writer thread is told it may drain, and
178
+ * this returns at once. Nothing is in the file because this returned, and
179
+ * nothing answers when the drain is over. The C++'s name for this call is
180
+ * `appender_flush`, and "flush" there said which mode the appender was opened
181
+ * in and not what the call does to the thread it was called on: the port names
182
+ * the drain by what the caller gets back, and what this one gives is no answer
183
+ * at all — hence "request", which is the one thing the two drains that do
184
+ * answer, `mars_xlog_flush_now_instance` and the awaited `flush()` every
185
+ * platform carries, do give. */
186
+ void mars_xlog_request_flush_instance(long long instance);
187
+
188
+ /* Drains an instance on the calling thread, which is what
189
+ * `appender_flush_sync` is: its records are on the disk when this returns, and
190
+ * that is a promise the requested call above does not make. */
191
+ void mars_xlog_flush_now_instance(long long instance);
192
+
193
+ /* SetConsoleLogOpen for an instance. */
194
+ void mars_xlog_set_console_log_instance(long long instance, int open);
195
+
196
+ /* SetMaxFileSize for an instance; 0 means "do not split". */
197
+ void mars_xlog_set_max_file_size_instance(long long instance, unsigned long long bytes);
198
+
199
+ /* SetMaxAliveTime for an instance; negative clamps to 0. */
200
+ void mars_xlog_set_max_alive_duration_instance(long long instance, long long seconds);
201
+
202
+ /**
203
+ * Replaces `mars::xlog::appender_make_logfile_name()`: the log file *name* for
204
+ * the day `timespan` days ago (0 = today), whether or not it exists yet.
205
+ *
206
+ * The C++ fills a `std::vector`; a C caller walks the same list with `index`,
207
+ * starting at 0 and stopping at MARS_XLOG_ERR_NO_PATH. `instance` is a handle
208
+ * from `mars_xlog_new_instance`; a handle no appender is open for answers
209
+ * MARS_XLOG_ERR_NO_PATH from the first index.
210
+ *
211
+ * @return the number of bytes written excluding the terminating NUL, or a
212
+ * negative MARS_XLOG_ERR_* code.
213
+ */
214
+ int mars_xlog_make_logfile_name_instance(long long instance,
215
+ int timespan,
216
+ unsigned int index,
217
+ char* out,
218
+ unsigned int len);
219
+
220
+ /**
221
+ * Replaces `mars::xlog::appender_getfilepath_from_timespan()`: the log files
222
+ * that *exist* for the day `timespan` days ago. Same `index` protocol as
223
+ * mars_xlog_make_logfile_name_instance.
224
+ */
225
+ int mars_xlog_getfilepath_from_timespan_instance(long long instance,
226
+ int timespan,
227
+ unsigned int index,
228
+ char* out,
229
+ unsigned int len);
230
+
231
+ /* The directory the appender of `instance` is writing its files to, or a negative
232
+ * MARS_XLOG_ERR_* code. A directory and not a file, which is what the C++'s
233
+ * `XloggerAppender::GetCurrentLogPath` answers — `sg_logdir`. A handle no
234
+ * appender is open for — `0` among them, since no symbol of this ABI installs
235
+ * a process-wide one — answers MARS_XLOG_ERR_NO_PATH. */
236
+ int mars_xlog_current_log_path_instance(long long instance, char* out, unsigned int len);
237
+
238
+ #ifdef __cplusplus
239
+ } /* extern "C" */
240
+ #endif
241
+
242
+ #endif /* MARS_XLOG_H_ */
@@ -0,0 +1,4 @@
1
+ module MarsRSFFI {
2
+ umbrella header "mars_xlog.h"
3
+ export *
4
+ }
@@ -0,0 +1,242 @@
1
+ /* Tencent is pleased to support the open source community by making Mars available.
2
+ * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
3
+ *
4
+ * Licensed under the MIT License (the "License"); you may not use this file except in
5
+ * compliance with the License. You may obtain a copy of the License at
6
+ * http://opensource.org/licenses/MIT
7
+ *
8
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
9
+ * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10
+ * either express or implied. See the License for the specific language governing permissions and
11
+ * limitations under the License.
12
+ */
13
+
14
+ /*
15
+ * mars_xlog.h — C ABI of the Rust xlog implementation (`marsrs-ffi`).
16
+ *
17
+ * This header is the drop-in seam for the existing C++ / JNI / ObjC layers of
18
+ * Mars. It mirrors the C++ surface of
19
+ *
20
+ * mars/xlog/appender.h (mars::xlog::appender_open / flush / close ...)
21
+ * mars/xlog/xlogger_interface.h (mars::xlog::XloggerWrite / SetLevel ...)
22
+ * mars/comm/xlogger/xloggerbase.h (TLogLevel)
23
+ *
24
+ * and is the C equivalent of the JNI bridge in mars/xlog/jni/Java2C_Xlog.cc.
25
+ *
26
+ * The header is hand-written and checked in next to the crate so that a C/C++
27
+ * caller can include it without running cbindgen. It is kept in sync with
28
+ * `src/abi.rs` by `tests/header_sync.rs`.
29
+ *
30
+ * Threading: every symbol may be called from any thread. The setters and the
31
+ * instance lifecycle mutate shared state (exactly like the C++ globals) and
32
+ * should be called from one place during start-up / shut-down. What no symbol
33
+ * here does is install a process-wide appender: an app opens an instance with
34
+ * `mars_xlog_new_instance` and writes through the handle it answers. Handle
35
+ * `0` names no appender at all — it is what an open that failed answers, and
36
+ * every symbol asked of it is a no-op.
37
+ *
38
+ * Panics: no Rust panic ever crosses this boundary. Every entry point is
39
+ * wrapped in `catch_unwind`; a panic is reported as `MARS_XLOG_ERR_PANIC` (or
40
+ * silently swallowed for the `void` symbols).
41
+ */
42
+
43
+ #ifndef MARS_XLOG_H_
44
+ #define MARS_XLOG_H_
45
+
46
+ /* The symbols this header declares are the ones `#[no_mangle]` exports: plain
47
+ * C names, and a C++ translation unit that includes this and calls
48
+ * `mars_xlog_new_instance()` asks its linker for a mangled one that does not
49
+ * exist.
50
+ * `mars_stn.h` and `mars_sdt.h` carry the same guard, and `mars_xlog.hpp` —
51
+ * the C++ face of this seam — includes this one, so a C++ caller asks for the
52
+ * same names whichever of the two it takes. */
53
+ #ifdef __cplusplus
54
+ extern "C" {
55
+ #endif
56
+
57
+ /* --- enums ------------------------------------------------------------- */
58
+
59
+ /** Mirrors `mars::xlog::TAppenderMode` (appender.h). */
60
+ typedef enum { MarsAppenderAsync = 0, MarsAppenderSync = 1 } MarsAppenderMode;
61
+
62
+ /** Mirrors `mars::xlog::TCompressMode` (appender.h). */
63
+ typedef enum { MarsCompressZlib = 0, MarsCompressZstd = 1 } MarsCompressMode;
64
+
65
+ /** Mirrors `TLogLevel` (xloggerbase.h); `kLevelAll == kLevelVerbose == 0`. */
66
+ typedef enum {
67
+ MarsLevelVerbose = 0,
68
+ MarsLevelDebug = 1,
69
+ MarsLevelInfo = 2,
70
+ MarsLevelWarn = 3,
71
+ MarsLevelError = 4,
72
+ MarsLevelFatal = 5
73
+ } MarsLogLevel;
74
+
75
+ /** Additional level understood only by the filter: disables every record. */
76
+ #define MARS_LEVEL_NONE 6
77
+
78
+ /* --- return codes -------------------------------------------------------
79
+ *
80
+ * The five from `NULL_CONFIG` to `APPENDER` are the reasons an open may be
81
+ * refused, and no symbol hands them out: `mars_xlog_new_instance` answers the
82
+ * handle `0` for every one of them, there being no room in a handle for a
83
+ * negative code. They are here for the caller that wants to name the reason in
84
+ * its own diagnostic, not to switch on an answer.
85
+ */
86
+ #define MARS_XLOG_OK 0
87
+ #define MARS_XLOG_ERR_NULL_CONFIG (-1) /* `config` was NULL */
88
+ #define MARS_XLOG_ERR_BAD_MODE (-2) /* `mode` outside MarsAppenderMode */
89
+ #define MARS_XLOG_ERR_BAD_COMPRESS (-3) /* `compress_mode` outside MarsCompressMode */
90
+ #define MARS_XLOG_ERR_EMPTY_LOG_DIR (-4) /* `log_dir` was NULL or "" */
91
+ #define MARS_XLOG_ERR_APPENDER (-5) /* the Rust appender refused the config */
92
+ #define MARS_XLOG_ERR_NULL_OUT (-6) /* `out` was NULL */
93
+ #define MARS_XLOG_ERR_NO_SPACE (-7) /* output buffer too small (0 or < need) */
94
+ #define MARS_XLOG_ERR_NO_PATH (-8) /* no current log file is open */
95
+ #define MARS_XLOG_ERR_PANIC (-99) /* a Rust panic was caught at the boundary */
96
+
97
+ /* --- config ------------------------------------------------------------- */
98
+
99
+ /**
100
+ * Mirrors `mars::xlog::XLogConfig` (appender.h) with C strings instead of
101
+ * `std::string`. Every pointer must be NUL-terminated UTF-8 or NULL; NULL is
102
+ * treated as "empty" (see the field docs) except for `log_dir`, which is
103
+ * mandatory.
104
+ */
105
+ typedef struct {
106
+ int mode; /* MarsAppenderMode; default when unset: Async */
107
+ const char* log_dir; /* mandatory, directory is created if missing */
108
+ const char* name_prefix; /* used verbatim; no default; "" is refused */
109
+ const char* pub_key; /* NULL / "" => logs are written unencrypted */
110
+ int compress_mode; /* MarsCompressMode; default when unset: Zlib */
111
+ int compress_level; /* <= 0 => keep the appender default (6) */
112
+ const char* cache_dir; /* NULL / "" => the mmap cache lives in log_dir */
113
+ int cache_days; /* < 0 => 0; 0 => keep every file */
114
+ } MarsXLogConfig;
115
+
116
+ /* ---- logger instances (mars::xlog::NewXloggerInstance and friends) ----
117
+ *
118
+ * Each instance owns an appender: its own log directory, prefix, key, mode and
119
+ * cache file. A C caller that wants a logger opens one with
120
+ * mars_xlog_new_instance and holds the handle it answers.
121
+ *
122
+ * Every call that can be asked of an instance exists only in this spelling:
123
+ * the C++ has a free function for its process-wide appender and a
124
+ * handle-taking one beside it, and a second spelling of the same operation
125
+ * here would be two ways to say one thing. There is no process-wide appender
126
+ * to install, so there is no free-function spelling either — and handle `0`,
127
+ * which is what a failed open answers, names no appender: the level, the mode,
128
+ * the console, the two sizes and the drain asked of it do nothing, and the
129
+ * questions answer "no" or `MARS_XLOG_ERR_NO_PATH`.
130
+ */
131
+
132
+ /* --- writing ------------------------------------------------------------- */
133
+
134
+ /* Returns the instance handle, or 0 on a null/invalid config. */
135
+ long long mars_xlog_new_instance(const MarsXLogConfig* config, int level);
136
+
137
+ /* The handle registered for name_prefix, or 0 when there is none. */
138
+ long long mars_xlog_get_instance(const char* name_prefix);
139
+
140
+ /* Releases the instance and closes its appender. Prefer the handle-aware
141
+ * mars_xlog_release_instance_of() when the caller holds an instance handle. */
142
+ void mars_xlog_release_instance(const char* name_prefix);
143
+
144
+ /* The same, and only while name_prefix is still registered under `instance`.
145
+ *
146
+ * Releasing takes the prefix and not the handle, so asking
147
+ * mars_xlog_get_instance and then calling mars_xlog_release_instance is two
148
+ * answers and not one: an open of the same prefix that lands between the two is
149
+ * handed a handle of its own, and the release closes that one. This is the
150
+ * question and the release in one call, which is also what makes a second
151
+ * close of a prefix a no-op however many callers hold its handle. */
152
+ void mars_xlog_release_instance_of(const char* name_prefix, long long instance);
153
+
154
+ /* Writes through an instance; honours the instance's level. */
155
+ void mars_xlog_write_instance(long long instance,
156
+ int level,
157
+ const char* tag,
158
+ const char* filename,
159
+ const char* func_name,
160
+ int line,
161
+ const char* log);
162
+
163
+ /* 1 when the instance would write this level, 0 otherwise. */
164
+ int mars_xlog_is_enabled_for(long long instance, int level);
165
+
166
+ /* The instance's level, or -1 for an unknown handle. */
167
+ int mars_xlog_get_level(long long instance);
168
+
169
+ /* SetLevel for an instance: the level `mars_xlog_get_level` and
170
+ * `mars_xlog_is_enabled_for` answer, and the one a write through the same
171
+ * handle asks. A no-op for handle `0`, which is no instance at all. */
172
+ void mars_xlog_set_level_instance(long long instance, int level);
173
+
174
+ /* appender_setmode / SetAppenderMode for an instance. */
175
+ void mars_xlog_set_mode_instance(long long instance, int mode);
176
+
177
+ /* Drains an instance, requested: the writer thread is told it may drain, and
178
+ * this returns at once. Nothing is in the file because this returned, and
179
+ * nothing answers when the drain is over. The C++'s name for this call is
180
+ * `appender_flush`, and "flush" there said which mode the appender was opened
181
+ * in and not what the call does to the thread it was called on: the port names
182
+ * the drain by what the caller gets back, and what this one gives is no answer
183
+ * at all — hence "request", which is the one thing the two drains that do
184
+ * answer, `mars_xlog_flush_now_instance` and the awaited `flush()` every
185
+ * platform carries, do give. */
186
+ void mars_xlog_request_flush_instance(long long instance);
187
+
188
+ /* Drains an instance on the calling thread, which is what
189
+ * `appender_flush_sync` is: its records are on the disk when this returns, and
190
+ * that is a promise the requested call above does not make. */
191
+ void mars_xlog_flush_now_instance(long long instance);
192
+
193
+ /* SetConsoleLogOpen for an instance. */
194
+ void mars_xlog_set_console_log_instance(long long instance, int open);
195
+
196
+ /* SetMaxFileSize for an instance; 0 means "do not split". */
197
+ void mars_xlog_set_max_file_size_instance(long long instance, unsigned long long bytes);
198
+
199
+ /* SetMaxAliveTime for an instance; negative clamps to 0. */
200
+ void mars_xlog_set_max_alive_duration_instance(long long instance, long long seconds);
201
+
202
+ /**
203
+ * Replaces `mars::xlog::appender_make_logfile_name()`: the log file *name* for
204
+ * the day `timespan` days ago (0 = today), whether or not it exists yet.
205
+ *
206
+ * The C++ fills a `std::vector`; a C caller walks the same list with `index`,
207
+ * starting at 0 and stopping at MARS_XLOG_ERR_NO_PATH. `instance` is a handle
208
+ * from `mars_xlog_new_instance`; a handle no appender is open for answers
209
+ * MARS_XLOG_ERR_NO_PATH from the first index.
210
+ *
211
+ * @return the number of bytes written excluding the terminating NUL, or a
212
+ * negative MARS_XLOG_ERR_* code.
213
+ */
214
+ int mars_xlog_make_logfile_name_instance(long long instance,
215
+ int timespan,
216
+ unsigned int index,
217
+ char* out,
218
+ unsigned int len);
219
+
220
+ /**
221
+ * Replaces `mars::xlog::appender_getfilepath_from_timespan()`: the log files
222
+ * that *exist* for the day `timespan` days ago. Same `index` protocol as
223
+ * mars_xlog_make_logfile_name_instance.
224
+ */
225
+ int mars_xlog_getfilepath_from_timespan_instance(long long instance,
226
+ int timespan,
227
+ unsigned int index,
228
+ char* out,
229
+ unsigned int len);
230
+
231
+ /* The directory the appender of `instance` is writing its files to, or a negative
232
+ * MARS_XLOG_ERR_* code. A directory and not a file, which is what the C++'s
233
+ * `XloggerAppender::GetCurrentLogPath` answers — `sg_logdir`. A handle no
234
+ * appender is open for — `0` among them, since no symbol of this ABI installs
235
+ * a process-wide one — answers MARS_XLOG_ERR_NO_PATH. */
236
+ int mars_xlog_current_log_path_instance(long long instance, char* out, unsigned int len);
237
+
238
+ #ifdef __cplusplus
239
+ } /* extern "C" */
240
+ #endif
241
+
242
+ #endif /* MARS_XLOG_H_ */
@@ -0,0 +1,4 @@
1
+ module MarsRSFFI {
2
+ umbrella header "mars_xlog.h"
3
+ export *
4
+ }
package/ios/Xlog.mm CHANGED
@@ -5,7 +5,7 @@
5
5
  // and jsi types. Neither has a Swift spelling: Swift's C++ interop stops at
6
6
  // templates and at the standard library. So what is here is the three things
7
7
  // React Native asks a module for and cannot read out of `Xlog.swift`, and the
8
- // eleven methods are there and not here.
8
+ // sixteen methods are there and not here.
9
9
  //
10
10
  // * `RCT_EXTERN_MODULE` registers the Swift class, which Swift cannot do for
11
11
  // itself — registration is a constructor the runtime runs, and a Swift class
@@ -18,7 +18,7 @@
18
18
  // * `methodQueue` answers `RCTJSThread`, the queue that is no queue: it is
19
19
  // what makes a TurboModule's methods run on the JS thread, so a call is made
20
20
  // where it is asked for and a method that answers a value answers it before
21
- // it returns. Without it the eleven would be dispatched to a queue of the
21
+ // it returns. Without it the sixteen would be dispatched to a queue of the
22
22
  // module's own and every answer would arrive as `undefined`.
23
23
  //
24
24
  // Objective-C++, and not Objective-C, because of the one `#include` a Swift