zacharycarter / zengine

2D | 3D Game development library
156 stars 13 forks source link

double logging #29

Open define-private-public opened 7 years ago

define-private-public commented 7 years ago

Whilst working on the ZSprite reader I noticed that some of my logging output to the console is being duplicated. E.g.:

INFO [TEX ID 1] Texture created successfully (1x1)
INFO [TEX ID 1] Texture created successfully (1x1)
INFO [TEX ID 1] Base white texture loaded successfully
INFO [TEX ID 1] Base white texture loaded successfully
DEBUG [VSHDR ID 1] Vertex shader compiled successfully
DEBUG [VSHDR ID 1] Vertex shader compiled successfully
DEBUG [VSHDR ID 2] Fragment shader compiled successfully
DEBUG [VSHDR ID 2] Fragment shader compiled successfully
DEBUG [SHDR ID 3] Shader program loaded successfully
DEBUG [SHDR ID 3] Shader program loaded successfully
INFO [VAO ID 1] Default buffers VAO initialized successfully (lines)
INFO [VAO ID 1] Default buffers VAO initialized successfully (lines)
INFO [VAO ID 2] Default buffers VAO initialized successfully (triangles)
INFO [VAO ID 2] Default buffers VAO initialized successfully (triangles)
INFO [VAO ID 3] Default buffers VAO initialized successfully (quads)
INFO [VAO ID 3] Default buffers VAO initialized successfully (quads)
INFO [TEX ID 2] Texture created successfully (128x128)
INFO [TEX ID 2] Texture created successfully (128x128)
INFO [TEX ID 2] Default font loaded successfully
INFO [TEX ID 2] Default font loaded successfully
INFO Detected v1.0 ZSprite in `../../specs/zsprite_examples/BlauGeist.zsprite`
INFO Detected v1.0 ZSprite in `../../specs/zsprite_examples/BlauGeist.zsprite`
INFO Spritesheet is at: ../../specs/zsprite_examples/blau_geist_sheet.png
INFO Spritesheet is at: ../../specs/zsprite_examples/blau_geist_sheet.png
INFO [TEX ID 4] Texture created successfully (232x29)
INFO [TEX ID 4] Texture created successfully (232x29)
DEBUG Didn't properly read a file.  Failed at state: ReadingSequenceInfo
DEBUG Didn't properly read a file.  Failed at state: ReadingSequenceInfo
INFO [TEX ID 2] Unloaded texture data from VRAM (GPU)
INFO [TEX ID 2] Unloaded texture data from VRAM (GPU)
INFO [TEX ID 1] Unloaded texture data (base white texture) from VRAM
INFO [TEX ID 1] Unloaded texture data (base white texture) from VRAM

Do you know what's causing this? If you take a look at the sprite.nim file in my #13 branch you'll see that I constructed another consoleLogger object. Could that be the culprit?

zacharycarter commented 7 years ago

I'm guessing so - I create one right when the engine starts so that'd be my guess. I can try experimenting by creating another one somewhere else, and seeing if I get similar behavior.

define-private-public commented 7 years ago

That's what I was thinking as well. When I was working on parsing I had all of the code I needed in sprite.nim, so I created a logger in that file, but when I had to start working with OpenGL objects I needed to create something that initialized the engine.

How easy would it be to implement a getLogger function that will ensure that only one logger is instantiated throughout its usage?

zacharycarter commented 7 years ago

We certainly can. I'll try to address this next.

zacharycarter commented 7 years ago

Alright I took a look at logging and I'm not sure what if anything we should do about it.

Right now the way things stand are - a console logger is created when the engine is initialized - so to use logging after initializing the engine, you should simply import the logging module and use the logging functions available to you.

In your case, where you were already working on code that used a logger and then you initialized zengine - I'm not sure what to do in that scenario. We can't check for existing loggers using the logging package so I guess we're boned.

I eventually think if we want to support things like webassembly, we'll have to get more creative with the approach to logging anyway.