Skip to content

Commit

Permalink
Improve/patch log parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
essenciary committed Jan 19, 2024
1 parent a4a0f1a commit a3df7ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GenieDevTools"
uuid = "4e5d9629-6565-4102-a9ff-45c707eb060e"
authors = ["essenciary <[email protected]> and contributors"]
version = "2.9.0"
version = "2.9.1"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
23 changes: 16 additions & 7 deletions src/GenieDevTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ function runhooks()
end
end

function tailapplog(handler::Function, logdirpath::String; frequency::Float64 = 0.5, env::AbstractString = "dev", remove_prefixes::Bool = true)
logpath = joinpath(logdirpath, "$env-$(Dates.today()).log")
function tailapplog(handler::Function,
logdirpath::String;
frequency::Float64 = 0.5,
env::AbstractString = "dev",
remove_prefixes::Bool = true,
logfile::AbstractString = "$env-$(Dates.today()).log",
skiptoend::Bool = true) :: Nothing
logpath = joinpath(logdirpath, logfile)

if ! isfile(logpath)
@warn "No log file found at $logpath"
return
Expand All @@ -38,11 +45,12 @@ function tailapplog(handler::Function, logdirpath::String; frequency::Float64 =
return
end

seekend(io)
skiptoend && seekend(io)
output = ""

while true
line = read(io, String)

if isempty(line)
sleep(frequency)
continue
Expand All @@ -64,10 +72,11 @@ function tailapplog(handler::Function, logdirpath::String; frequency::Float64 =
end

if remove_prefixes
line = replace(line, "^└" => "")
line = replace(line, "^┌" => "")
line = replace(line, "`" => '"')
line = replace(line, "^\\[" => "")
line = replace(line, r"^└ " => "")
line = replace(line, r"^┌ " => "")
line = replace(line, r"`" => '"')
line = replace(line, r"^\[ " => "")
line = replace(line, r"^│ " => "")
end

output = output * line * "\n"
Expand Down

2 comments on commit a3df7ca

@essenciary
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/99154

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.9.1 -m "<description of version>" a3df7ca56139d66a14614532afc051f0fc3359b1
git push origin v2.9.1

Please sign in to comment.