Skip to content

Commit

Permalink
new: added support for ecs logs format
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed Dec 9, 2023
1 parent e7acfb9 commit 3dc833c
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 88 deletions.
17 changes: 4 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ categories = ["command-line-utilities"]
description = "Utility for viewing json-formatted log files."
keywords = ["cli", "human", "log"]
name = "hl"
version = "0.21.0"
version = "0.22.0"
edition = "2021"
build = "build.rs"

Expand Down
61 changes: 61 additions & 0 deletions etc/defaults/config-ecs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Time format, see https://man7.org/linux/man-pages/man1/date.1.html for details.
time-format: '%b %d %T.%3N'

# Time zone name, see column "TZ identifier" at
# https://en.wikipedia.org/wiki/List_of_tz_database_time_zones page.
time-zone: UTC

# Settings for fields processing.
fields:
# Configuration of the predefined set of fields.
predefined:
time:
names: ['@timestamp']
logger:
names: [log.logger]
level:
variants:
- names: [log.level]
values:
debug: [debug, dbg, d]
info: [info, inf, i, informational]
warning: [warning, warn, wrn, w]
error: [error, err, fatal, critical, panic, e]
message:
names: [message]
caller:
names: []
caller-file:
names: [log.origin.file.name]
caller-line:
names: [log.origin.file.line]
# List of wildcard field names to ignore.
ignore: ['_*']
# List of exact field names to hide.
hide:
- log

# Formatting settings.
formatting:
punctuation:
logger-name-separator: ':'
field-key-value-separator: '='
string-opening-quote: "'"
string-closing-quote: "'"
source-location-separator: '@ '
hidden-fields-indicator: ' ...'
level-left-separator: '|'
level-right-separator: '|'
input-number-prefix: '#'
input-number-left-separator: ''
input-number-right-separator: ' | '
input-name-left-separator: ''
input-name-right-separator: ' | '
input-name-clipping: '...'
input-name-common-part: '...'

# Number of processing threads, configured automatically based on CPU count if not specified.
concurrency: ~

# Currently selected theme.
theme: universal
4 changes: 4 additions & 0 deletions etc/defaults/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ fields:
names: [msg, message, MESSAGE, Message]
caller:
names: [caller, CALLER, Caller]
caller-file:
names: []
caller-line:
names: []
# List of wildcard field names to ignore.
ignore: ['_*']
# List of exact field names to hide.
Expand Down
19 changes: 15 additions & 4 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::theme;
use crate::IncludeExcludeKeyFilter;
use datefmt::DateTimeFormatter;
use fmtx::{aligned_left, centered};
use model::Level;
use model::{Caller, Level};
use theme::{Element, StylingPush, Theme};

// ---
Expand Down Expand Up @@ -176,14 +176,25 @@ impl RecordFormatter {
//
// caller
//
if let Some(text) = rec.caller {
if let Some(caller) = &rec.caller {
s.element(Element::Caller, |s| {
s.batch(|buf| {
buf.push(b' ');
buf.extend_from_slice(self.cfg.punctuation.source_location_separator.as_bytes())
});
s.element(Element::CallerInner, |s| {
s.batch(|buf| buf.extend_from_slice(text.as_bytes()))
s.batch(|buf| {
match caller {
Caller::Text(text) => {
buf.extend_from_slice(text.as_bytes());
}
Caller::FileLine(file, line) => {
buf.extend_from_slice(file.as_bytes());
buf.push(b':');
buf.extend_from_slice(line.as_bytes());
}
};
});
});
});
};
Expand Down Expand Up @@ -491,7 +502,7 @@ mod tests {
message: Some(RawValue::from_string(r#""tm""#.into()).unwrap().as_ref()),
level: Some(Level::Debug),
logger: Some("tl"),
caller: Some("tc"),
caller: Some(Caller::Text("tc")),
extra: heapless::Vec::from_slice(&[
("ka", RawValue::from_string(r#"{"va":{"kb":42}}"#.into()).unwrap().as_ref()),
]).unwrap(),
Expand Down
Loading

0 comments on commit 3dc833c

Please sign in to comment.