refactor: derustification
This commit is contained in:
@@ -11,7 +11,6 @@
|
|||||||
buildInputs =
|
buildInputs =
|
||||||
(with self.packages.${system}; [
|
(with self.packages.${system}; [
|
||||||
nvim-alias
|
nvim-alias
|
||||||
#prettify-log
|
|
||||||
nvim-pager
|
nvim-pager
|
||||||
])
|
])
|
||||||
++ (with pkgs; [
|
++ (with pkgs; [
|
||||||
|
|||||||
21
flake.lock
generated
21
flake.lock
generated
@@ -248,7 +248,7 @@
|
|||||||
"home-manager": {
|
"home-manager": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"nixpkgs"
|
"nixpkgs-fixed"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
@@ -709,6 +709,22 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nixpkgs-fixed": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1771419570,
|
||||||
|
"narHash": "sha256-bxAlQgre3pcQcaRUm/8A0v/X8d2nhfraWSFqVmMcBcU=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "6d41bc27aaf7b6a3ba6b169db3bd5d6159cfaa47",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-25.11",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1771419570,
|
"lastModified": 1771419570,
|
||||||
@@ -729,7 +745,7 @@
|
|||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-parts": "flake-parts_2",
|
"flake-parts": "flake-parts_2",
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"nixpkgs"
|
"nixpkgs-fixed"
|
||||||
],
|
],
|
||||||
"nuschtosSearch": "nuschtosSearch",
|
"nuschtosSearch": "nuschtosSearch",
|
||||||
"systems": "systems_5"
|
"systems": "systems_5"
|
||||||
@@ -806,6 +822,7 @@
|
|||||||
"nixos-anywhere": "nixos-anywhere",
|
"nixos-anywhere": "nixos-anywhere",
|
||||||
"nixos-hardware": "nixos-hardware",
|
"nixos-hardware": "nixos-hardware",
|
||||||
"nixpkgs": "nixpkgs_2",
|
"nixpkgs": "nixpkgs_2",
|
||||||
|
"nixpkgs-fixed": "nixpkgs-fixed",
|
||||||
"nixvim": "nixvim",
|
"nixvim": "nixvim",
|
||||||
"rust-overlay": "rust-overlay",
|
"rust-overlay": "rust-overlay",
|
||||||
"sops-nix": "sops-nix"
|
"sops-nix": "sops-nix"
|
||||||
|
|||||||
@@ -56,9 +56,6 @@ in {
|
|||||||
yq-go
|
yq-go
|
||||||
jq
|
jq
|
||||||
htop-vim
|
htop-vim
|
||||||
])
|
|
||||||
++ (with self.packages.${pkgs.system}; [
|
|
||||||
prettify-log
|
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,9 +56,9 @@
|
|||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
gdb
|
gdb
|
||||||
hectic.nvim-pager
|
hectic.nvim-pager
|
||||||
(writeScriptBin "check" ''
|
#(writeScriptBin "check" ''
|
||||||
journalctl -u postgresql.service | grep postgresql-post-start | sed 's|psql:/nix/store/[^:]*:[0-9]*: ||' | sed 's|^[^:]*:[^:]*:[^:]*: ||' | grep -v '^\[.*\]' | ${hectic.prettify-log}/bin/prettify-log --color-output
|
# journalctl -u postgresql.service | grep postgresql-post-start | sed 's|psql:/nix/store/[^:]*:[0-9]*: ||' | sed 's|^[^:]*:[^:]*:[^:]*: ||' | grep -v '^\[.*\]' | ${hectic.prettify-log}/bin/prettify-log --color-output
|
||||||
'')
|
#'')
|
||||||
];
|
];
|
||||||
programs.zsh.shellAliases = self.lib.sharedShellAliasesForDevVm // {
|
programs.zsh.shellAliases = self.lib.sharedShellAliasesForDevVm // {
|
||||||
conn = "sudo su postgres -c 'psql -p 64317'";
|
conn = "sudo su postgres -c 'psql -p 64317'";
|
||||||
|
|||||||
@@ -125,7 +125,6 @@ in {
|
|||||||
github-gh-tl = pkgs.callPackage ./github/gh-tl.nix {};
|
github-gh-tl = pkgs.callPackage ./github/gh-tl.nix {};
|
||||||
supabase-with-env-collection = pkgs.callPackage ./supabase-with-env-collection.nix {};
|
supabase-with-env-collection = pkgs.callPackage ./supabase-with-env-collection.nix {};
|
||||||
migration-name = pkgs.callPackage ./migration-name.nix {};
|
migration-name = pkgs.callPackage ./migration-name.nix {};
|
||||||
prettify-log = pkgs.callPackage ./prettify-log/default.nix rust.commonArgs;
|
|
||||||
pg-from = pkgs.callPackage ./postgres/pg-from/default.nix rust.commonArgs;
|
pg-from = pkgs.callPackage ./postgres/pg-from/default.nix rust.commonArgs;
|
||||||
pg-schema = pkgs.callPackage ./postgres/pg-schema/default.nix rust.commonArgs;
|
pg-schema = pkgs.callPackage ./postgres/pg-schema/default.nix rust.commonArgs;
|
||||||
pg_wdumpall = pkgs.callPackage ./postgres/pg_wdumpall.nix rust.commonArgs;
|
pg_wdumpall = pkgs.callPackage ./postgres/pg_wdumpall.nix rust.commonArgs;
|
||||||
|
|||||||
497
package/prettify-log/Cargo.lock
generated
497
package/prettify-log/Cargo.lock
generated
@@ -1,497 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 3
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aho-corasick"
|
|
||||||
version = "1.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "anstyle"
|
|
||||||
version = "1.0.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "assert_cmd"
|
|
||||||
version = "2.0.16"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dc1835b7f27878de8525dc71410b5a31cdcc5f230aed5ba5df968e09c201b23d"
|
|
||||||
dependencies = [
|
|
||||||
"anstyle",
|
|
||||||
"bstr",
|
|
||||||
"doc-comment",
|
|
||||||
"libc",
|
|
||||||
"predicates",
|
|
||||||
"predicates-core",
|
|
||||||
"predicates-tree",
|
|
||||||
"wait-timeout",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "atty"
|
|
||||||
version = "0.2.14"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
|
||||||
dependencies = [
|
|
||||||
"hermit-abi",
|
|
||||||
"libc",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "autocfg"
|
|
||||||
version = "1.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitflags"
|
|
||||||
version = "2.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bstr"
|
|
||||||
version = "1.11.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "531a9155a481e2ee699d4f98f43c0ca4ff8ee1bfd55c31e9e98fb29d2b176fe0"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
"regex-automata",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "colored_json"
|
|
||||||
version = "5.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e35980a1b846f8e3e359fd18099172a0857140ba9230affc4f71348081e039b6"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"yansi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "difflib"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "doc-comment"
|
|
||||||
version = "0.3.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "errno"
|
|
||||||
version = "0.3.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fastrand"
|
|
||||||
version = "2.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "float-cmp"
|
|
||||||
version = "0.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b09cf3155332e944990140d967ff5eceb70df778b34f77d8075db46e4704e6d8"
|
|
||||||
dependencies = [
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "getrandom"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"libc",
|
|
||||||
"wasi",
|
|
||||||
"windows-targets",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hermit-abi"
|
|
||||||
version = "0.1.19"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itoa"
|
|
||||||
version = "1.0.14"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libc"
|
|
||||||
version = "0.2.169"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "linux-raw-sys"
|
|
||||||
version = "0.4.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memchr"
|
|
||||||
version = "2.7.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "normalize-line-endings"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-traits"
|
|
||||||
version = "0.2.19"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "once_cell"
|
|
||||||
version = "1.20.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "predicates"
|
|
||||||
version = "3.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a5d19ee57562043d37e82899fade9a22ebab7be9cef5026b07fda9cdd4293573"
|
|
||||||
dependencies = [
|
|
||||||
"anstyle",
|
|
||||||
"difflib",
|
|
||||||
"float-cmp",
|
|
||||||
"normalize-line-endings",
|
|
||||||
"predicates-core",
|
|
||||||
"regex",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "predicates-core"
|
|
||||||
version = "1.0.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "727e462b119fe9c93fd0eb1429a5f7647394014cf3c04ab2c0350eeb09095ffa"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "predicates-tree"
|
|
||||||
version = "1.0.12"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "72dd2d6d381dfb73a193c7fca536518d7caee39fc8503f74e7dc0be0531b425c"
|
|
||||||
dependencies = [
|
|
||||||
"predicates-core",
|
|
||||||
"termtree",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "prettify-log"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"assert_cmd",
|
|
||||||
"atty",
|
|
||||||
"colored_json",
|
|
||||||
"float-cmp",
|
|
||||||
"once_cell",
|
|
||||||
"predicates",
|
|
||||||
"regex",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"tempfile",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.93"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.38"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex"
|
|
||||||
version = "1.11.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
|
||||||
dependencies = [
|
|
||||||
"aho-corasick",
|
|
||||||
"memchr",
|
|
||||||
"regex-automata",
|
|
||||||
"regex-syntax",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex-automata"
|
|
||||||
version = "0.4.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
|
||||||
dependencies = [
|
|
||||||
"aho-corasick",
|
|
||||||
"memchr",
|
|
||||||
"regex-syntax",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex-syntax"
|
|
||||||
version = "0.8.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rustix"
|
|
||||||
version = "0.38.44"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"errno",
|
|
||||||
"libc",
|
|
||||||
"linux-raw-sys",
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ryu"
|
|
||||||
version = "1.0.19"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde"
|
|
||||||
version = "1.0.217"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
|
|
||||||
dependencies = [
|
|
||||||
"serde_derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_derive"
|
|
||||||
version = "1.0.217"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_json"
|
|
||||||
version = "1.0.138"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949"
|
|
||||||
dependencies = [
|
|
||||||
"itoa",
|
|
||||||
"memchr",
|
|
||||||
"ryu",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "2.0.96"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tempfile"
|
|
||||||
version = "3.16.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "38c246215d7d24f48ae091a2902398798e05d978b24315d6efbc00ede9a8bb91"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"fastrand",
|
|
||||||
"getrandom",
|
|
||||||
"once_cell",
|
|
||||||
"rustix",
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "termtree"
|
|
||||||
version = "0.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-ident"
|
|
||||||
version = "1.0.16"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wait-timeout"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasi"
|
|
||||||
version = "0.13.3+wasi-0.2.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2"
|
|
||||||
dependencies = [
|
|
||||||
"wit-bindgen-rt",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi"
|
|
||||||
version = "0.3.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
|
||||||
dependencies = [
|
|
||||||
"winapi-i686-pc-windows-gnu",
|
|
||||||
"winapi-x86_64-pc-windows-gnu",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-i686-pc-windows-gnu"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-x86_64-pc-windows-gnu"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-sys"
|
|
||||||
version = "0.59.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
|
||||||
dependencies = [
|
|
||||||
"windows-targets",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-targets"
|
|
||||||
version = "0.52.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
|
||||||
dependencies = [
|
|
||||||
"windows_aarch64_gnullvm",
|
|
||||||
"windows_aarch64_msvc",
|
|
||||||
"windows_i686_gnu",
|
|
||||||
"windows_i686_gnullvm",
|
|
||||||
"windows_i686_msvc",
|
|
||||||
"windows_x86_64_gnu",
|
|
||||||
"windows_x86_64_gnullvm",
|
|
||||||
"windows_x86_64_msvc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_aarch64_gnullvm"
|
|
||||||
version = "0.52.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_aarch64_msvc"
|
|
||||||
version = "0.52.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_i686_gnu"
|
|
||||||
version = "0.52.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_i686_gnullvm"
|
|
||||||
version = "0.52.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_i686_msvc"
|
|
||||||
version = "0.52.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_gnu"
|
|
||||||
version = "0.52.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_gnullvm"
|
|
||||||
version = "0.52.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_msvc"
|
|
||||||
version = "0.52.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wit-bindgen-rt"
|
|
||||||
version = "0.33.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "yansi"
|
|
||||||
version = "1.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049"
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "prettify-log"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
atty = "0.2.14"
|
|
||||||
colored_json = "5.0.0"
|
|
||||||
once_cell = "1.20.2"
|
|
||||||
regex = "1.11.1"
|
|
||||||
serde = "1.0.217"
|
|
||||||
serde_json = "1.0.138"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
assert_cmd = "2.0.16"
|
|
||||||
predicates = "3.1.3"
|
|
||||||
float-cmp = "0.10.0"
|
|
||||||
tempfile = "3.16.0"
|
|
||||||
|
|
||||||
[[test]]
|
|
||||||
name = "test_prettify"
|
|
||||||
path = "test/prettify.rs"
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
cargoToml,
|
|
||||||
nativeBuildInputs,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}: let
|
|
||||||
src = ./.;
|
|
||||||
cargo = cargoToml src;
|
|
||||||
in
|
|
||||||
pkgs.rustPlatform.buildRustPackage {
|
|
||||||
pname = cargo.package.name;
|
|
||||||
version = cargo.package.version;
|
|
||||||
|
|
||||||
inherit nativeBuildInputs src;
|
|
||||||
|
|
||||||
cargoLock.lockFile = ./Cargo.lock;
|
|
||||||
|
|
||||||
doCheck = true;
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
use std::io::{self, BufRead};
|
|
||||||
use std::env;
|
|
||||||
use serde_json::Value;
|
|
||||||
use colored_json::{ColorMode, ToColoredJson};
|
|
||||||
use regex::{Regex, Captures};
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
|
|
||||||
/// Finds the first '{' and tries to match nested braces until the corresponding '}'.
|
|
||||||
fn find_json_block(line: &str) -> Option<(usize, usize)> {
|
|
||||||
let start = line.find('{')?;
|
|
||||||
let mut brace_count = 0;
|
|
||||||
for (i, ch) in line[start..].char_indices() {
|
|
||||||
match ch {
|
|
||||||
'{' => brace_count += 1,
|
|
||||||
'}' => {
|
|
||||||
brace_count -= 1;
|
|
||||||
if brace_count == 0 {
|
|
||||||
return Some((start, start + i + 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
static RE: Lazy<Regex> = Lazy::new(|| {
|
|
||||||
Regex::new(r"(?i)(^|[^A-Za-z])(?P<kw>ERROR|DEBUG|INFO|LOG|EXCEPTION|WARNING|NOTICE|HINT|FATAL|DETAIL|STATEMENT)(:)").unwrap()
|
|
||||||
});
|
|
||||||
|
|
||||||
/// Applies color to known log keywords (e.g. ERROR, DEBUG) without coloring the colon.
|
|
||||||
/// Captures the preceding boundary, the keyword, and the colon, then colors only the keyword.
|
|
||||||
fn colorize_keywords(line: &str) -> String {
|
|
||||||
let red = "\x1b[31m";
|
|
||||||
let blue = "\x1b[34m";
|
|
||||||
let green = "\x1b[32m";
|
|
||||||
let yellow = "\x1b[33m";
|
|
||||||
let magenta = "\x1b[35m";
|
|
||||||
let cyan = "\x1b[36m";
|
|
||||||
let reset = "\x1b[0m";
|
|
||||||
|
|
||||||
RE.replace_all(line, |caps: &Captures| {
|
|
||||||
let prefix = caps.get(1).unwrap().as_str();
|
|
||||||
let keyword = caps.name("kw").unwrap().as_str();
|
|
||||||
let suffix = caps.get(3).unwrap().as_str();
|
|
||||||
let key = match keyword.to_lowercase().as_str() {
|
|
||||||
"error" => format!("{}{}{}{}", prefix, red, keyword, reset),
|
|
||||||
"debug" => format!("{}{}{}{}", prefix, blue, keyword, reset),
|
|
||||||
"info" | "log"
|
|
||||||
=> format!("{}{}{}{}", prefix, green, keyword, reset),
|
|
||||||
"exception" | "fatal"
|
|
||||||
=> format!("{}{}{}{}", prefix, magenta, keyword, reset),
|
|
||||||
"warning" => format!("{}{}{}{}", prefix, yellow, keyword, reset),
|
|
||||||
"notice" | "hint" | "detail" | "statement"
|
|
||||||
=> format!("{}{}{}{}", prefix, cyan, keyword, reset),
|
|
||||||
_ => caps[0].to_string(),
|
|
||||||
};
|
|
||||||
key + suffix
|
|
||||||
}).to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn conditionally_colorize_keywords<'a>(line: &'a str, force_color: bool) -> String {
|
|
||||||
if force_color {
|
|
||||||
colorize_keywords(&line)
|
|
||||||
} else if atty::is(atty::Stream::Stdout) {
|
|
||||||
colorize_keywords(&line)
|
|
||||||
} else {
|
|
||||||
line.to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
|
||||||
let mut force_color = false;
|
|
||||||
for arg in env::args().skip(1) {
|
|
||||||
if arg == "--color-output" {
|
|
||||||
force_color = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let stdin = io::stdin();
|
|
||||||
for line_result in stdin.lock().lines() {
|
|
||||||
let line = line_result?;
|
|
||||||
if let Some((start, end)) = find_json_block(&line) {
|
|
||||||
let candidate = &line[start..end];
|
|
||||||
if let Ok(json) = serde_json::from_str::<Value>(candidate) {
|
|
||||||
let pretty = serde_json::to_string_pretty(&json).unwrap();
|
|
||||||
|
|
||||||
let colorized = if force_color {
|
|
||||||
pretty.to_colored_json(ColorMode::On).unwrap()
|
|
||||||
} else {
|
|
||||||
pretty.to_colored_json_auto().unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
let prefix = conditionally_colorize_keywords(&line[..start], force_color);
|
|
||||||
let suffix = conditionally_colorize_keywords(&line[end..], force_color);
|
|
||||||
println!("{}{}{}", prefix, colorized, suffix);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no valid JSON found or parsing fails, print unchanged
|
|
||||||
println!("{}", conditionally_colorize_keywords(&line, force_color));
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
[34mDebug[0m: respons [1m{[0m
|
|
||||||
[1;34m"[0m[1;34msome[0m[1;34m"[0m: [32m"[0m[32mname[0m[32m"[0m,
|
|
||||||
[1;34m"[0m[1;34mvalue[0m[1;34m"[0m: 12[1m
|
|
||||||
}[0m is received
|
|
||||||
{timespan} [32mInfo[0m: some log without json
|
|
||||||
[31mError[0m: [1m{[0m
|
|
||||||
[1;34m"[0m[1;34mcode[0m[1;34m"[0m: 500,
|
|
||||||
[1;34m"[0m[1;34merror[0m[1;34m"[0m: [32m"[0m[32mSomething went wrong[0m[32m"[0m[1m
|
|
||||||
}[0m
|
|
||||||
[33mWarning[0m: Invalid data format detected
|
|
||||||
[1m{[0m
|
|
||||||
[1;34m"[0m[1;34mdata[0m[1;34m"[0m: [1m{[0m
|
|
||||||
[1;34m"[0m[1;34mid[0m[1;34m"[0m: 1,
|
|
||||||
[1;34m"[0m[1;34mname[0m[1;34m"[0m: [32m"[0m[32mtest[0m[32m"[0m[1m
|
|
||||||
}[0m,
|
|
||||||
[1;34m"[0m[1;34mstatus[0m[1;34m"[0m: [32m"[0m[32mok[0m[32m"[0m[1m
|
|
||||||
}[0m
|
|
||||||
User [32mlog[0m: [1m{[0m
|
|
||||||
[1;34m"[0m[1;34maction[0m[1;34m"[0m: [32m"[0m[32mlogin[0m[32m"[0m,
|
|
||||||
[1;34m"[0m[1;34mtimestamp[0m[1;34m"[0m: [32m"[0m[32m2025-01-31T12:00:00Z[0m[32m"[0m,
|
|
||||||
[1;34m"[0m[1;34muser[0m[1;34m"[0m: [32m"[0m[32mjohn_doe[0m[32m"[0m[1m
|
|
||||||
}[0m
|
|
||||||
Random text without json
|
|
||||||
[34mDebug[0m: Payload sent: [1m{[0m
|
|
||||||
[1;34m"[0m[1;34mrequest[0m[1;34m"[0m: [1m{[0m
|
|
||||||
[1;34m"[0m[1;34mbody[0m[1;34m"[0m: [1m{[0m
|
|
||||||
[1;34m"[0m[1;34mkey[0m[1;34m"[0m: [32m"[0m[32mvalue[0m[32m"[0m[1m
|
|
||||||
}[0m,
|
|
||||||
[1;34m"[0m[1;34mtype[0m[1;34m"[0m: [32m"[0m[32mPOST[0m[32m"[0m[1m
|
|
||||||
}[0m[1m
|
|
||||||
}[0m
|
|
||||||
Another line with no json
|
|
||||||
{meta} [32mLog[0m: {"action": "update", "success": true}
|
|
||||||
Normal message with [1m{[0m
|
|
||||||
[1;34m"[0m[1;34mjson[0m[1;34m"[0m: [32m"[0m[32minside[0m[32m"[0m[1m
|
|
||||||
}[0m text
|
|
||||||
[1m{[0m
|
|
||||||
[1;34m"[0m[1;34marray[0m[1;34m"[0m: [1m[[0m
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3[1m
|
|
||||||
][0m,
|
|
||||||
[1;34m"[0m[1;34mnested[0m[1;34m"[0m: [1m{[0m
|
|
||||||
[1;34m"[0m[1;34mdeep[0m[1;34m"[0m: [1m{[0m
|
|
||||||
[1;34m"[0m[1;34mvalue[0m[1;34m"[0m: [32m"[0m[32mfound[0m[32m"[0m[1m
|
|
||||||
}[0m[1m
|
|
||||||
}[0m[1m
|
|
||||||
}[0m
|
|
||||||
{2025-01-31} Event: {"event": "created", "user": "admin"}
|
|
||||||
Plain text that should not be modified
|
|
||||||
[32mInfo[0m: [1m{[0m
|
|
||||||
[1;34m"[0m[1;34mdetails[0m[1;34m"[0m: [32m"[0m[32mthis is a test log[0m[32m"[0m,
|
|
||||||
[1;34m"[0m[1;34mlevel[0m[1;34m"[0m: [32m"[0m[32minfo[0m[32m"[0m[1m
|
|
||||||
}[0m
|
|
||||||
[1m{[0m
|
|
||||||
[1;34m"[0m[1;34marray[0m[1;34m"[0m: [1m[[0m
|
|
||||||
[1m{[0m
|
|
||||||
[1;34m"[0m[1;34mid[0m[1;34m"[0m: 1[1m
|
|
||||||
}[0m,
|
|
||||||
[1m{[0m
|
|
||||||
[1;34m"[0m[1;34mid[0m[1;34m"[0m: 2[1m
|
|
||||||
}[0m,
|
|
||||||
[1m{[0m
|
|
||||||
[1;34m"[0m[1;34mid[0m[1;34m"[0m: 3[1m
|
|
||||||
}[0m[1m
|
|
||||||
][0m[1m
|
|
||||||
}[0m
|
|
||||||
An unformatted json log [1m{[0m
|
|
||||||
[1;34m"[0m[1;34mname[0m[1;34m"[0m: [32m"[0m[32mexample[0m[32m"[0m,
|
|
||||||
[1;34m"[0m[1;34mvalid[0m[1;34m"[0m: true[1m
|
|
||||||
}[0m
|
|
||||||
[34mDebug[0m: [1m{[0m
|
|
||||||
[1;34m"[0m[1;34mdata[0m[1;34m"[0m: [32m"[0m[32mtest[0m[32m"[0m,
|
|
||||||
[1;34m"[0m[1;34mitems[0m[1;34m"[0m: [1m[[0m
|
|
||||||
[1m{[0m
|
|
||||||
[1;34m"[0m[1;34mx[0m[1;34m"[0m: 10,
|
|
||||||
[1;34m"[0m[1;34my[0m[1;34m"[0m: 20[1m
|
|
||||||
}[0m[1m
|
|
||||||
][0m[1m
|
|
||||||
}[0m
|
|
||||||
Non-json message with curly braces {like this}
|
|
||||||
[1m{[0m
|
|
||||||
[1;34m"[0m[1;34mkey1[0m[1;34m"[0m: [32m"[0m[32mvalue1[0m[32m"[0m,
|
|
||||||
[1;34m"[0m[1;34mkey2[0m[1;34m"[0m: [1m{[0m
|
|
||||||
[1;34m"[0m[1;34msubkey[0m[1;34m"[0m: [32m"[0m[32msubvalue[0m[32m"[0m[1m
|
|
||||||
}[0m[1m
|
|
||||||
}[0m
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
Debug: respons {
|
|
||||||
"some": "name",
|
|
||||||
"value": 12
|
|
||||||
} is received
|
|
||||||
{timespan} Info: some log without json
|
|
||||||
Error: {
|
|
||||||
"code": 500,
|
|
||||||
"error": "Something went wrong"
|
|
||||||
}
|
|
||||||
Warning: Invalid data format detected
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"id": 1,
|
|
||||||
"name": "test"
|
|
||||||
},
|
|
||||||
"status": "ok"
|
|
||||||
}
|
|
||||||
User log: {
|
|
||||||
"action": "login",
|
|
||||||
"timestamp": "2025-01-31T12:00:00Z",
|
|
||||||
"user": "john_doe"
|
|
||||||
}
|
|
||||||
Random text without json
|
|
||||||
Debug: Payload sent: {
|
|
||||||
"request": {
|
|
||||||
"body": {
|
|
||||||
"key": "value"
|
|
||||||
},
|
|
||||||
"type": "POST"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Another line with no json
|
|
||||||
{meta} Log: {"action": "update", "success": true}
|
|
||||||
Normal message with {
|
|
||||||
"json": "inside"
|
|
||||||
} text
|
|
||||||
{
|
|
||||||
"array": [
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3
|
|
||||||
],
|
|
||||||
"nested": {
|
|
||||||
"deep": {
|
|
||||||
"value": "found"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{2025-01-31} Event: {"event": "created", "user": "admin"}
|
|
||||||
Plain text that should not be modified
|
|
||||||
Info: {
|
|
||||||
"details": "this is a test log",
|
|
||||||
"level": "info"
|
|
||||||
}
|
|
||||||
{
|
|
||||||
"array": [
|
|
||||||
{
|
|
||||||
"id": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 3
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
An unformatted json log {
|
|
||||||
"name": "example",
|
|
||||||
"valid": true
|
|
||||||
}
|
|
||||||
Debug: {
|
|
||||||
"data": "test",
|
|
||||||
"items": [
|
|
||||||
{
|
|
||||||
"x": 10,
|
|
||||||
"y": 20
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Non-json message with curly braces {like this}
|
|
||||||
{
|
|
||||||
"key1": "value1",
|
|
||||||
"key2": {
|
|
||||||
"subkey": "subvalue"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
Debug: respons {"some": "name", "value": 12} is received
|
|
||||||
{timespan} Info: some log without json
|
|
||||||
Error: {"error": "Something went wrong", "code": 500}
|
|
||||||
Warning: Invalid data format detected
|
|
||||||
{"status": "ok", "data": {"id": 1, "name": "test"}}
|
|
||||||
User log: {"user": "john_doe", "action": "login", "timestamp": "2025-01-31T12:00:00Z"}
|
|
||||||
Random text without json
|
|
||||||
Debug: Payload sent: {"request": {"type": "POST", "body": {"key": "value"}}}
|
|
||||||
Another line with no json
|
|
||||||
{meta} Log: {"action": "update", "success": true}
|
|
||||||
Normal message with {"json": "inside"} text
|
|
||||||
{"nested": {"deep": {"value": "found"}}, "array": [1,2,3]}
|
|
||||||
{2025-01-31} Event: {"event": "created", "user": "admin"}
|
|
||||||
Plain text that should not be modified
|
|
||||||
Info: {"level": "info", "details": "this is a test log"}
|
|
||||||
{"array": [{"id": 1}, {"id": 2}, {"id": 3}]}
|
|
||||||
An unformatted json log {"name":"example","valid":true}
|
|
||||||
Debug: {"data": "test", "items": [{"x": 10, "y": 20}]}
|
|
||||||
Non-json message with curly braces {like this}
|
|
||||||
{"key1": "value1", "key2": {"subkey": "subvalue"}}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
use std::fs;
|
|
||||||
use std::process::Command;
|
|
||||||
use std::io::Write;
|
|
||||||
use tempfile::NamedTempFile;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_prettify() {
|
|
||||||
let input_file = "test/fixture/test.log";
|
|
||||||
let expected_output = fs::read_to_string("test/fixture/expected.log")
|
|
||||||
.expect("Failed to read expected.log");
|
|
||||||
|
|
||||||
let mut actual_output_file = NamedTempFile::new().expect("Failed to create temp file");
|
|
||||||
|
|
||||||
let output = Command::new("cargo")
|
|
||||||
.args(&["run", "--quiet"])
|
|
||||||
.stdin(fs::File::open(input_file).expect("Failed to open test.log"))
|
|
||||||
.output()
|
|
||||||
.expect("Failed to run prettify_logs");
|
|
||||||
|
|
||||||
assert!(output.status.success());
|
|
||||||
|
|
||||||
actual_output_file
|
|
||||||
.write_all(&output.stdout)
|
|
||||||
.expect("Failed to write output");
|
|
||||||
|
|
||||||
let actual_output = String::from_utf8_lossy(&output.stdout);
|
|
||||||
|
|
||||||
assert_eq!(actual_output.trim(), expected_output.trim(), "Output does not match expected.log");
|
|
||||||
|
|
||||||
if actual_output.trim() != expected_output.trim() {
|
|
||||||
eprintln!(
|
|
||||||
"Test failed! Actual output saved to: {}",
|
|
||||||
actual_output_file.path().display()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_prettify_colored() {
|
|
||||||
let input_file = "test/fixture/test.log";
|
|
||||||
let expected_output = fs::read_to_string("test/fixture/expected-colored.log")
|
|
||||||
.expect("Failed to read expected.log");
|
|
||||||
|
|
||||||
let mut actual_output_file = NamedTempFile::new().expect("Failed to create temp file");
|
|
||||||
|
|
||||||
let output = Command::new("cargo")
|
|
||||||
.args(&["run", "--quiet", "--", "--color-output"])
|
|
||||||
.stdin(fs::File::open(input_file).expect("Failed to open test.log"))
|
|
||||||
.output()
|
|
||||||
.expect("Failed to run prettify_logs");
|
|
||||||
|
|
||||||
assert!(output.status.success());
|
|
||||||
|
|
||||||
actual_output_file
|
|
||||||
.write_all(&output.stdout)
|
|
||||||
.expect("Failed to write output");
|
|
||||||
|
|
||||||
let actual_output = String::from_utf8_lossy(&output.stdout);
|
|
||||||
|
|
||||||
assert_eq!(actual_output.trim(), expected_output.trim(), "Output does not match expected.log");
|
|
||||||
|
|
||||||
if actual_output.trim() != expected_output.trim() {
|
|
||||||
eprintln!(
|
|
||||||
"Test failed! Actual output saved to: {}",
|
|
||||||
actual_output_file.path().display()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user