Skip to content

Commit fa6fde2

Browse files
authored
Merge pull request #44 from kescobo/reexport-logging
Re-export Logging.jl
2 parents 42b639b + f58fd39 commit fa6fde2

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "0.4.5"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
8+
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
89

910
[compat]
1011
julia = "0.7, 1"

README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ ConsoleLogger(stream, min_level) =
5050

5151
# Usage
5252
Load the package with `using LoggingExtras`.
53-
You likely also want to load the `Logging` standard lib.
54-
Loggers can be constructed and used like normal.
53+
For convenience, this also re-exports the `Logging` standard library.
5554

5655

5756
### Basics of working with loggers
@@ -154,7 +153,7 @@ see the HTTP example below.
154153
Another example is using them to stop messages every being repeated within a given time period.
155154
156155
```julia
157-
using Dates, Logging, LoggingExtras
156+
using Dates, LoggingExtras
158157

159158
julia> function make_throttled_logger(period)
160159
history = Dict{Symbol, DateTime}()
@@ -196,7 +195,7 @@ that just checks if the level of the message is above the level specified when i
196195
### Demo: filter out all the log messages that are less severe than `Error`
197196
198197
```julia
199-
julia> using Logging, LoggingExtras
198+
julia> using LoggingExtras
200199

201200
julia> error_only_logger = MinLevelLogger(current_logger(), Logging.Error);
202201

@@ -222,7 +221,7 @@ and should return a new modified named tuple.
222221
A simple example of its use is truncating messages.
223222
224223
```julia
225-
julia> using Logging, LoggingExtras
224+
julia> using LoggingExtras
226225

227226
julia> truncating_logger = TransformerLogger(global_logger()) do log
228227
if length(log.message) > 128
@@ -263,7 +262,7 @@ We are going to log info and above to one file,
263262
and warnings and above to another.
264263
265264
```julia
266-
julia> using Logging; using LoggingExtras;
265+
julia> using LoggingExtras;
267266

268267
julia> demux_logger = TeeLogger(
269268
MinLevelLogger(FileLogger("info.log"), Logging.Info),
@@ -299,7 +298,7 @@ when the `DateFormat` would change the filename. Note that if you wish to have
299298
escape them so they are not interpreted by the `DateFormat` code. Example:
300299
301300
```julia
302-
julia> using Logging, LoggingExtras
301+
julia> using LoggingExtras
303302

304303
julia> rotating_logger = DatetimeRotatingFileLogger(pwd(), raw"\a\c\c\e\s\s-YYYY-mm-dd-HH-MM-SS.\l\o\g");
305304

@@ -327,7 +326,7 @@ The `FormatLogger` is a sink that formats the message and prints to a wrapped IO
327326
Formatting is done by providing a function `f(io::IO, log_args::NamedTuple)`.
328327
329328
```julia
330-
julia> using Logging, LoggingExtras
329+
julia> using LoggingExtras
331330

332331
julia> logger = FormatLogger() do io, args
333332
println(io, args._module, " | ", "[", args.level, "] ", args.message)
@@ -347,7 +346,6 @@ Main | [Warn] This is a warning, should take a look.
347346
348347
```julia
349348
using LoggingExtras
350-
using Logging
351349

352350
function sensible_message_filter(log)
353351
length(log.message) < 1028
@@ -361,7 +359,6 @@ global_logger(ActiveFilteredLogger(sensible_message_filter, global_logger()))
361359
362360
```julia
363361
using LoggingExtras
364-
using Logging
365362
using HTTP
366363

367364
function not_HTTP_message_filter(log)
@@ -375,7 +372,6 @@ global_logger(EarlyFilteredLogger(not_HTTP_message_filter, global_logger()))
375372
376373
```julia
377374
using LoggingExtras
378-
using Logging
379375
using HTTP
380376

381377
transformer_logger(global_logger()) do log
@@ -394,7 +390,7 @@ global_logger(transformer_logger)
394390
## Add timestamp to all logging
395391
396392
```julia
397-
using Logging, LoggingExtras, Dates
393+
using LoggingExtras, Dates
398394

399395
const date_format = "yyyy-mm-dd HH:MM:SS"
400396

src/LoggingExtras.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ export TeeLogger, TransformerLogger, FileLogger,
1212
ActiveFilteredLogger, EarlyFilteredLogger, MinLevelLogger,
1313
DatetimeRotatingFileLogger, FormatLogger
1414

15+
######
16+
# Re export Logging.jl from stdlib
17+
# list is stable between julia 1.0 and 1.6
18+
# https://github.com/JuliaLang/julia/blob/release-1.6/stdlib/Logging/src/Logging.jl#L32-L46
19+
using Logging
20+
21+
export Logging, AbstractLogger, LogLevel, NullLogger,
22+
@debug, @info, @warn, @error, @logmsg,
23+
with_logger, current_logger, global_logger, disable_logging,
24+
SimpleLogger, ConsoleLogger
1525

1626
######
1727
# Utilities for dealing with compositional loggers.

0 commit comments

Comments
 (0)