# How to catch stdout per module?

**URL:** <https://discourse.julialang.org/t/how-to-catch-stdout-per-module/59611>\
**Category:** General Usage\
**Tags:** question, logging\
**Created:** [April 19, 2021, 7:45pm UTC](https://discourse.julialang.org/t/how-to-catch-stdout-per-module/59611 "2021-04-19T19:45:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)\
**Post date:** [April 19, 2021, 7:45pm UTC](https://discourse.julialang.org/t/how-to-catch-stdout-per-module/59611/1 "2021-04-19T19:45:27Z")

</div>

If I want to run unrelated tasks and output stdout over the network how would I capture stdout in a module without another module stealing it?

As I see it there is only one Base.stdout, which is the default for println. As a backup there is also Core.stdout, but I think this should not be touched. How would one implement println per module to use a module owned stdout.

```julia
module A
const stdout = redirect_stdout()
print() = println("Mod A")
end
module B
const stdout = redirect_stdout()
print() = println("Mod B")
end
A.print()
B.print()
readline(A.stdout[1])
# is empty
readline(B.stdout[1])
# Mod A
readline(A.stdout[1])
# Mod B

```

Another idea is writing to a file and overwriting print functions, but maybe there is a more elegant way.

```julia
module A
    const out = mktemp()
    print(txt) = Base.print(out[2],txt)
    function generate()
        print("test1")
        println("test2")
        @show a=3
    end
    function get()
        seek(out[2],0)
        read(out[2],String)    
    end
    println(txt) = Base.println(out[2],txt)
end
A.generate()
# a = 3 = 3
# 3
A.get()
# "test1test2\n"

```
