better log
This commit is contained in:
@@ -900,7 +900,11 @@ function build_sink_routing() {
|
||||
if (!is_array(sink.exclude)) sink.exclude = []
|
||||
if (is_text(sink.stack)) sink.stack = [sink.stack]
|
||||
if (!is_array(sink.stack)) sink.stack = []
|
||||
if (sink.type == "file" && sink.path) ensure_log_dir(sink.path)
|
||||
if (sink.type == "file" && sink.path) {
|
||||
ensure_log_dir(sink.path)
|
||||
if (sink.mode == "overwrite")
|
||||
fd.slurpwrite(sink.path, stone(_make_blob("")))
|
||||
}
|
||||
arrfor(sink.stack, function(ch) {
|
||||
stack_channels[ch] = true
|
||||
})
|
||||
@@ -936,6 +940,12 @@ function load_log_config() {
|
||||
}
|
||||
}
|
||||
build_sink_routing()
|
||||
var names = array(log_config.sink)
|
||||
arrfor(names, function(name) {
|
||||
var sink = log_config.sink[name]
|
||||
if (sink.type == "file")
|
||||
os.print("[log] " + name + " -> " + sink.path + "\n")
|
||||
})
|
||||
}
|
||||
|
||||
function pretty_format(rec) {
|
||||
@@ -1001,6 +1011,7 @@ function sink_excluded(sink, channel) {
|
||||
|
||||
function dispatch_to_sink(sink, rec) {
|
||||
var line = null
|
||||
var st = null
|
||||
if (sink_excluded(sink, rec.channel)) return
|
||||
if (sink.type == "console") {
|
||||
if (sink.format == "json")
|
||||
@@ -1013,7 +1024,12 @@ function dispatch_to_sink(sink, rec) {
|
||||
os.print(pretty_format(rec))
|
||||
} else if (sink.type == "file") {
|
||||
line = json.encode(rec, false) + "\n"
|
||||
fd.slurpappend(sink.path, stone(blob(line)))
|
||||
if (sink.max_size) {
|
||||
st = fd.stat(sink.path)
|
||||
if (st && st.size > sink.max_size)
|
||||
fd.slurpwrite(sink.path, stone(_make_blob("")))
|
||||
}
|
||||
fd.slurpappend(sink.path, stone(_make_blob(line)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user