BazerUtils.jl

Assorted Julia utilities including custom logging
Log | Files | Refs | README | LICENSE

README.md (4929B)


      1 # BazerUtils.jl
      2 
      3 
      4 [![CI](https://github.com/louloulibs/BazerUtils.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/louloulibs/BazerUtils.jl/actions/workflows/CI.yml)
      5 [![Lifecycle:Experimental](https://img.shields.io/badge/Lifecycle-Experimental-339999)](https://github.com/louloulibs/BazerUtils.jl/actions/workflows/CI.yml)
      6 [![codecov](https://codecov.io/gh/louloulibs/BazerUtils.jl/graph/badge.svg?token=53QO3HSSRT)](https://codecov.io/gh/louloulibs/BazerUtils.jl)
      7 
      8 
      9 
     10 `BazerUtils.jl` is a package that assembles various functionality that I use on a frequent basis in julia.
     11 It is a more mature version of [`Prototypes.jl`](https://github.com/louloulibs/Prototypes.jl) where I try a bunch of things out (there is overlap).
     12 
     13 
     14 The package provides:
     15 
     16    - [`custom_logger`](#custom-logging): configurable logging with per-level file output, module filtering, and multiple format options (`:pretty`, `:oneline`, `:json`, `:logfmt`, `:syslog`, `:log4j_standard`)
     17    - ~~`read_jsonl` / `stream_jsonl` / `write_jsonl`~~: **deprecated** — use [`JSON.jl`](https://github.com/JuliaIO/JSON.jl) v1 with `jsonlines=true` instead
     18 
     19 
     20 ## Installation
     21 
     22 `BazerUtils.jl` is a registered package.
     23 You can install from the my julia registry [`loulouJL`](https://github.com/LouLouLibs/loulouJL) via the julia package manager:
     24 ```julia
     25 > using Pkg, LocalRegistry
     26 > pkg"registry add https://github.com/LouLouLibs/loulouJL.git"
     27 > Pkg.add("BazerUtils")
     28 ```
     29 
     30 If you don't want to add a new registry, you can install it directly from github:
     31 ```julia
     32 > import Pkg; Pkg.add("https://github.com/louloulibs/BazerUtils.jl#main")
     33 ```
     34 
     35 
     36 ## Usage
     37 
     38 
     39 ### Custom Logging
     40 
     41 A configurable logger that lets you filter messages from specific modules and redirect them to different files, with a format that is easy to read and control.
     42 
     43 ```julia
     44 custom_logger(
     45     "./log/build_stable_sample_multiplier";
     46     file_loggers=[:warn, :debug],                             # which file loggers to deploy
     47 
     48     filtered_modules_all=[:HTTP],                             # filter across all loggers
     49     filtered_modules_specific=[:TranscodingStreams],           # filter for stdout and info only
     50 
     51     displaysize=(50,100),                                     # how much to show for non-string messages
     52     log_format=:oneline,                                      # format for files (see formats below)
     53     log_format_stdout=:pretty,                                # format for REPL
     54 
     55     cascading_loglevels=false,                                # false = each file gets only its level
     56                                                               # true  = each file gets its level and above
     57 
     58     create_log_files=true,                                    # separate file per level
     59     overwrite=true,
     60     );
     61 ```
     62 
     63 #### Log Formats
     64 
     65 | Format | Symbol | Description |
     66 |--------|--------|-------------|
     67 | **Pretty** | `:pretty` | Box-drawing + ANSI colors — default for stdout |
     68 | **Oneline** | `:oneline` | Single-line with timestamp, level, module, file:line — default for files |
     69 | **JSON** | `:json` | One JSON object per line — for log aggregation (ELK, Datadog, Loki) |
     70 | **logfmt** | `:logfmt` | `key=value` pairs — grep-friendly, popular with Splunk/Heroku |
     71 | **Syslog** | `:syslog` | RFC 5424 syslog format |
     72 | **Log4j Standard** | `:log4j_standard` | Apache Log4j PatternLayout — for Java tooling interop |
     73 
     74 Example output for each:
     75 
     76 ```
     77 # :pretty (stdout default)
     78 ┌ [08:28:08 2025-02-12] Info |  @ Main[script.jl:42]
     79 └ Processing batch 5 of 10
     80 
     81 # :oneline (file default)
     82 [/home/user/project] 2025-02-12 08:28:08 INFO  Main[./script.jl:42] Processing batch 5 of 10
     83 
     84 # :json
     85 {"timestamp":"2025-02-12T08:28:08","level":"INFO","module":"Main","file":"script.jl","line":42,"message":"Processing batch 5 of 10"}
     86 
     87 # :logfmt
     88 ts=2025-02-12T08:28:08 level=info module=Main file=script.jl line=42 msg="Processing batch 5 of 10"
     89 
     90 # :syslog
     91 <14>1 2025-02-12T08:28:08 hostname julia 12345 - - Processing batch 5 of 10
     92 
     93 # :log4j_standard
     94 2025-02-12 08:28:08,000 INFO  [1] Main - Processing batch 5 of 10
     95 ```
     96 
     97 > **Note:** `:log4j` still works as a deprecated alias for `:oneline` and will be removed in a future version.
     98 
     99 
    100 ### JSON Lines (deprecated)
    101 
    102 The JSONL functions (`read_jsonl`, `stream_jsonl`, `write_jsonl`) are deprecated.
    103 Use [`JSON.jl`](https://github.com/JuliaIO/JSON.jl) v1 instead:
    104 ```julia
    105 using JSON
    106 data = JSON.parse("data.jsonl"; jsonlines=true)       # read
    107 JSON.json("out.jsonl", data; jsonlines=true)           # write
    108 ```
    109 
    110 
    111 ## Other stuff
    112 
    113 
    114 See my other package
    115   - [BazerData.jl](https://github.com/louloulibs/BazerData.jl) which groups together data wrangling functions.
    116   - [FinanceRoutines.jl](https://github.com/louloulibs/FinanceRoutines.jl) which is more focused and centered on working with financial data.
    117   - [TigerFetch.jl](https://github.com/louloulibs/TigerFetch.jl) which simplifies downloading shape files from the Census.