Skip to content

Commit ddd4502

Browse files
author
zhengzhiyong
committed
changes: add autonl config
1 parent f2086aa commit ddd4502

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.org

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ end
203203

204204
如果 =true= ,会在发往kafka前添加机器名。
205205

206+
*** autonl
207+
可选项 boolean 默认 ~autonl=true~
208+
209+
如果 =true= ,会在发往kafka的行尾添加换行。
210+
206211
* 性能
207212
15万行每秒。有需要可以继续优化。
208213

src/tail2kafka.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ struct LuaCtx {
124124
bool withhost;
125125
bool withtime;
126126
int timeidx;
127+
bool autonl;
127128

128129
uint32_t addr;
129130
bool autoparti;
@@ -168,6 +169,7 @@ LuaCtx::LuaCtx()
168169
autoparti = false;
169170
partition = RD_KAFKA_PARTITION_UA;
170171
timeidx = UNSET_INT;
172+
autonl = true;
171173
rawcopy = false;
172174

173175
buffer = new char[MAX_LINE_LEN];
@@ -572,6 +574,16 @@ static LuaCtx *loadLuaCtx(CnfCtx *cnfCtx, const char *file, char *errbuf)
572574
}
573575
lua_settop(L, 0);
574576

577+
lua_getglobal(L, "autonl");
578+
if (!lua_isnil(L, 1)) {
579+
if (!lua_isboolean(L, 1)) {
580+
snprintf(errbuf, MAX_ERR_LEN, "%s autonl must be boolean", file);
581+
goto error;
582+
}
583+
ctx->autonl = lua_toboolean(L, 1);
584+
}
585+
lua_settop(L, 0);
586+
575587
lua_getglobal(L, "withhost");
576588
if (!lua_isnil(L, 1)) {
577589
if (!lua_isboolean(L, 1)) {
@@ -1539,7 +1551,7 @@ bool processLine(LuaCtx *ctx, char *line, size_t nline)
15391551
}
15401552
} else {
15411553
req.data = new std::string(line, nline);
1542-
req.data->append(1, '\n');
1554+
if (ctx->autonl) req.data->append(1, '\n');
15431555
rc = true;
15441556
}
15451557

0 commit comments

Comments
 (0)