• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
TTT_Dutch

How to Log and stay Modular

56 posts in this topic

[quote name='alnite' timestamp='1315765297' post='4860401']
If you want more complex behavior[/quote]

Something struck me recently. Many companies advertise: "... complex solutions..." I suppose simple solutions to complex problems don't sell. What I want is dead simple behavior that cannot be messed up, either now or somewhere far along the line.


Major thing that is painfully missing in such debates is what constitutes a "module". C++ only knows compilation unit and process.


If we define per-system logging, things become much clearer. If we want Physics, Input and Renderer systems to have modular logging, then each of these has its own. What does this mean? Several ways:[code]struct System {
public const char * LOG_SYSTEM_NAME = "System";
};
..
struct System {
Logger logger;
};

System::Logger logger = "System";
...[/code]
The thing we need in common is a tag unique to system which we append to logs. Logs are typically text files on disk. Tag must be immutable since it will outlive the process by far, so whatever can be done while the code is running is just the birth of a log.

It may seem like deciding upon this tag is the big challenge now, making sure it's unique, but the tag itself, its location and name will be implicitly determine by logical dependencies of the project itself. If suddenly Input wants to log as Renderer, there is something weird going on and in reverse - Input will never need access to Renderer log. If it does, we got emergent complexity of InputRenderer, which is more of a design issue to worry than how the log is stored.

And by implication - if all tags are stored in some global file, we succumb to the God Class or "#include <everywhere.h>" problem, where modularity was lost already - a single change in that file affects everything.
--------
Log aggregation needs to be addressed next. At simplest level each system logs to its own file. We might choose each run to create its own instance in which case filename needs to be stateful in system implementation. Something like:[code]Logger logger("SYSTEM", Date.now());[/code]

Problem of uniqueness now becomes an issue (the static/global/singleton problem). Maybe we add process or machine ID to that. Benefit of this - ability to directly store all logs.

A minor triviality that needs to be solved is how to initialize such system, we might want log location to be externally specified. Again, passing a Config struct or having command-line parser set some common fields works, but one can wrap this into full IoC design. As mentioned, IoC is most intrusive and may not enable third-party libraries to use it.
-------
Advanced logging:
Let's say our logging is not boring, and we track a bunch of stuff, user actions, transactions, etc... with goal of running ETL. The idea of logging straight to database might be tempting in this case and is often done for web services but it's just implementation detail. Typical stumbling blocks here will involve configuration parsing and sequential initialization (config comes from database but to talk to database we need to read config, or database connection may drop or database may become unresponsive).

With the last two issues we come back to state. Stateful loggers are hard and if they hiccup, the application stops.

For this reason we want whatever "tags" our loggers use to be immutable per some unique context (see process, etc.). This way, logging can continue without regard to state (database/file are state) and we can even make use of fragments.

Also, see various logging services provided by OS which prevent logs from overflowing, but useful logs might not be

Then there's fancy fast stuff, such as K/V database (redis, mongo, etc...) which may be good fit with stateless loggers but may be at odds with ETL. Dumb SQL table or flat files might still be simplest way.
-------
Q: "I know, I'll log as XML or HTML"
A: "Any time your application exits unexpectedly (the time you need logs most) the log will not be valid XML and HTML" Don't add complexity - XML/HTML are stateful - the depth and nesting need to be properly terminated which can only happen under ideal circumstances.

Q: "But good logging system will make debugging easy"
A: "No, it will never log the correct information, use debugger or printf, the data will be discarded after each run anyway"

Q: "So, which option is the best"
A: "Depends on goals and how pragmatical one is"

--------
PS: If logging, start each line/entry with date/time in standardized format: YYYYMMDDThhmmss.msecZ. The reason - they are naturally ordered and can be compared using any strcmp algorithm to produce correct ordering. It makes searching easy (str > "2009" && str < "2010") will return expected range using just about any text mangling tool.
0

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1315762645' post='4860383']
*snip*

My preferred solution is to invert the relationship between the [i]code doing the logging[/i] (call it the "client") and the [i]logging system itself [/i](call it the "provider"). Most solutions involve the client telling the provider where to log, etc. at the point of invocation (or nearby if you're using constructors and logging objects). To me this seems brittle; if you suddenly want all of your graphics-related logging to go to foo.txt instead of bar.txt, have fun updating your 500 constructor calls across the project!

*snip*
[/quote]
I completely agree with the snipped out portions. The only problem I have with the one paragraph I've left in is the part about updating 500 constructor calls. The reason is: yes, a system designed like that is horrible in my opinion, and so it shouldn't exist in the first place. What I usually mean when it comes to logging systems with objects is essentially what you've described, except where each "channel" is a separate Logger object. Only one per channel. And they're global. So there's only one constructor for each channel (and there shouldn't be that many channels, and they should all be initialized in the same spot). That way, each Logger/Channel encapsulates whatever data it needs to store. And logging with the system is just a simple function call (via the channel logger's member method), something like globalSystemLog.Log("I'm logging this now"). Which is basically the same as a free function (someNamespace::log(LOG_SYSTEM, "I'm logging this now")), only the channel is now a global Logger object rather than an enum being passed to a global logging function.

[quote name='Antheus' timestamp='1315772593' post='4860433']
*snip*
[/quote]
Yeah, I agree with you in pretty much every sense.
0

Share this post


Link to post
Share on other sites
I still don't see any [i]benefit[/i] to using a global object over a free function. Of course I realize they're isomorphic at a certain point, that was never under contention; my dispute with people who use global objects is that there doesn't seem to actually be a reason to have an object to begin with!

You also better hope that nobody [i]besides[/i] your logging system uses global objects, or you get a wonderful static order of initialization SNAFU and life is miserable.


A free function minimizes potential points of failure. It also provides a very clean, natural way to serialize log requests, which is [i]essential[/i] in multithreaded systems. Nothing sucks like trying to unravel a log file that has three threads stomping on each others' output. Of course you technically [i]can[/i] serialize requests made by multiple redundant logger objects, but it's more complex - more possible ways to get it wrong. Why subject yourself to that? Why not do the simplest thing that gets the job done?


I'm not just being argumentative for the hell of it, by the way. I genuinely do not understand the mentality of programmers who do not treat implementation complexity as their enemy.
1

Share this post


Link to post
Share on other sites
The OP could have written a logging system many times over in the time this thread has taken. I think we have run into the bikeshed principle here.

OP: Use free functions. Forget modularity. Then get on with the real work, of which actual logging is probably a tiny fraction.
1

Share this post


Link to post
Share on other sites
[quote name='speciesUnknown' timestamp='1315795766' post='4860532']
The OP could have written a logging system many times over in the time this thread has taken. I think we have run into the bikeshed principle here.

OP: Use free functions. Forget modularity. Then get on with the real work, of which actual logging is probably a tiny fraction.
[/quote]

Done. :)
0

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1315762645' post='4860383']
Most solutions involve the client telling the provider where to log, etc. at the point of invocation (or nearby if you're using constructors and logging objects). To me this seems brittle; if you suddenly want all of your graphics-related logging to go to foo.txt instead of bar.txt, have fun updating your 500 constructor calls across the project!
[/quote]

Amen, brother. That seems like a poor design choice. (Or perhaps more accurately, it's "lack of design.")


[quote name='ApochPiQ' timestamp='1315762645' post='4860383']
Sure, if your logger needs to store state, then by all means use a lightweight object to do so; that's fine by me. (I'm skeptical that 99% of the loggers written would ever need to store any state, and that last 1% better be darn convincing, but I wouldn't rule it out entirely.)
[/quote]

Like I said,

[quote name='VReality' timestamp='1315536514' post='4859326']
The problem with logs in videogame development isn't that no one needs them, it's that they quickly become unusable as they get spammed by every system under development.
[/quote]

When you make a logging system on a full-team development project, within about ten minutes it's being spammed with so much diagnostic information that it becomes nearly useless. So then everyone decides that you shouldn't check in any code containing log calls unless there's a really good reason. Then it takes a good half an hour to an hour for it to become unusable again. Then you do code reviews and don't [i][b]allow [/b][/i]any log calls to be checked in unless there's a very good reason, and this time it takes a good week to a week and a half before you lose your diagnostic info in the noise.

The solution to that - er wait. I should say, [i][b]A [/b][/i]solution to that is to make logging locally configurable.

First, I would introduce logging channels. And I wouldn't use enums. I would allow any arbitrary string to identify a channel, so that at any point a developer could make up a new channel for their own purposes without touching logging system code.

Second, I would make a config file (not shared under revision control) that could optionally exist at a known location, in which they could put entries sending arbitrary channels to various destinations, e.g "AI" to be displayed in-game, "Memory Manager" to be saved to a file, "Network" to be sent to the debug console, etc.

All the systems under development would still post logs with simple calls to free functions which did not store any state. And the application, or logging system, or whatever, could optionally create a single logging system object with which to manipulate and store state, e.g. by loading and applying that config file, passing the object around and making configuration calls on it, etc. It seems right to have only a single instance, but there's no reason to make it global or to create it statically.

This gives users flexibility, freedom, and control, to log arbitrarily and to different destinations, and to see exactly the information they're interested in, without the noise. In other words, it makes logs usable. And it does so without the need to add objects or state to the actual logging interface used by the systems generating log calls.

Now, as written, just about none of the logging systems I've seen in use felt the need to store state...

[indent=1][size=3]But pretty much every logging system I've seen really [i][b]needed [/b][/i]to start storing state to avoid becoming instantly useless.[/size]
[/indent]
0

Share this post


Link to post
Share on other sites
I think this is just a minor discrepancy in terminology. Sure, the [i]process of logging and routing and viewing the logs[/i] taken as a whole has stateful components. I'm not disputing the utility of that.

The [i]act of writing a single entry to a log[/i] does not, and should not IMO, involve state, and therefore encapsulation as an object is nonsensical.

Of course, my philosophy on logging generally boils down to "spam away, and use better log viewing tools."
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0