# Understanding Logging in Julia

**URL:** <https://discourse.julialang.org/t/understanding-logging-in-julia/34252>\
**Category:** General Usage\
**Created:** [February 6, 2020, 2:35pm UTC](https://discourse.julialang.org/t/understanding-logging-in-julia/34252 "2020-02-06T14:35:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregstrq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregstrq/32/20620_2.png) [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Post date:** [February 6, 2020, 2:35pm UTC](https://discourse.julialang.org/t/understanding-logging-in-julia/34252/1 "2020-02-06T14:35:33Z")

</div>

Hi, guys.  
I am trying to understand how to use Julia Logging system. For that I am now reading through the julia docs and the corresponding source code.

I have a question about the implementation of SimpleLogger (see [logger.jl](https://github.com/JuliaLang/julia/blob/master/base/logging.jl)). In the function `handle_message`, instead of writing all the messages directly to IOStream, the messages are first written into an additional IOBuffer and then the contents of the IOBuffer are copied to the IOStream.

What are the benefits of such design?

---

<div class="post-metadata">

**Author:** ![Dictino](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dictino/32/217281_2.png) [@Dictino](https://discourse.julialang.org/u/Dictino)\
**Post date:** [February 6, 2020, 3:17pm UTC](https://discourse.julialang.org/t/understanding-logging-in-julia/34252/2 "2020-02-06T15:17:45Z")

</div>

To do I/O you need to call the Operating System and this Syscall have some overhead, this is what write does on a IOStream (actually it call the C function that in turn call the OS).

Buffers are often used to group multiple I/O operations in a single Syscall to reduce this overhead.

The idea is to accumulate the data you want to write in memory (the IOBuffer) and, when there are enough data to write, transfer this chunk of data to the IOStream.
