# Logging with custom messages

**URL:** <https://discourse.julialang.org/t/logging-with-custom-messages/62637>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 9, 2021, 6:17pm UTC](https://discourse.julialang.org/t/logging-with-custom-messages/62637 "2021-06-09T18:17:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enrique](https://avatars.discourse-cdn.com/v4/letter/e/b9bd4f/32.png) [@Enrique](https://discourse.julialang.org/u/Enrique)\
**Post date:** [June 9, 2021, 6:17pm UTC](https://discourse.julialang.org/t/logging-with-custom-messages/62637/1 "2021-06-09T18:17:39Z")

</div>

Hello Julia community,

I read the logging documentation, but I am still struggling to create a custom logger. Basically, what I want to do is to replicate what I do in python, that is, to create a logger on info level, but to show the function name, line number, time that the line was executed, and the message. In python, it would be something like:

```julia
fmt_file = (
    "%(levelname)s %(asctime)s [%(filename)s:%(funcName)s:%(lineno)d] %(message)s"
)
file_formatter = logging.Formatter(fmt_file, "%Y-%m-%d %H:%M:%S")

```

In Julia, I tried:

```julia
@logmsg Logging.Info "Message" _line= __LINE__

```

but it does not print the line.

Can you let me know how I can make this to work, or what other approach I can use?

Thanks in advance for any help or insight that you can provide.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [June 10, 2021, 12:30am UTC](https://discourse.julialang.org/t/logging-with-custom-messages/62637/2 "2021-06-10T00:30:08Z")

</div>

How about this?

```julia
using Logging, LoggingExtras, Dates

logger = FormatLogger(stderr) do io, args
    print(io, args.level, " ")
    Dates.format(io, now(), dateformat"yyyy-mm-dd HH:MM:SS")
    print(io, " [", args.file, ":", args.line, "] ")
    println(io, args.message)
end

global_logger(logger)

@debug "hello debug message"
@info "hello info message"
@warn "hello warning message"
@error "hello error message"

```

with output

```shell
$ julia run.jl 
Debug 2021-06-10 22:27:58 [/tmp/run.jl:12] hello debug message
Info 2021-06-10 22:27:58 [/tmp/run.jl:13] hello info message
Warn 2021-06-10 22:27:58 [/tmp/run.jl:14] hello warning message
Error 2021-06-10 22:27:58 [/tmp/run.jl:15] hello error message

```

---

<div class="post-metadata">

**Author:** ![Enrique](https://avatars.discourse-cdn.com/v4/letter/e/b9bd4f/32.png) [@Enrique](https://discourse.julialang.org/u/Enrique)\
**Post date:** [June 10, 2021, 1:27am UTC](https://discourse.julialang.org/t/logging-with-custom-messages/62637/3 "2021-06-10T01:27:26Z")

</div>

Fredrik, thank you so much! this is exactly what I was looking for 👏
