Log4J 4 You

June 9, 2014 at 8:42 am (Computer Science, Java, Processing, Programming, Teaching) (, , , , , , )


Last weekend I added logging to my game engine since I finally got fed up with print logging to console. I’ve waited this long because while it was on my To-Do list, it kept getting pushed back because it isn’t as interesting of a task as rendering a new HUD for example. It is definitely worth investing in though! If you don’t have logging in your game, I suggest you do it now!

In this post, I will talk about setting up Log4J to use in either Java or Processing programs. Furthermore, I will show you how to set up loggers programmatically. Typically you will see guides that reference config files or XML for setting up loggers. I chose to do it programmatically because I wanted to set it up early in my engine code, have it trickle down into all of the other layers, and not have to change the configurations very often. Perhaps this isn’t a good enough reason to do what I did, but at least for my situation I didn’t mind using it.

Before I get into how to do it this way, I will warn you of one of the major drawbacks of doing this: you can’t change the default logging levels without recompiling your code. This is actually a big deal for many projects, but for some not so much. One of the advantages of doing it programmatically however, especially with Processing sketches, is that once you set up a Log4J library you can copy and paste code and it will just work. No configuration files required.

Enough talk! Lets see some how-to!

 

Add Library (For Processing sketches only)

If you are setting up Log4J for use in Processing sketches, you first need to create a Library. There are many guides on how to do this, so I will just give an overview. After you download a log4j JAR file, navigate to your “libraries” folder (I forget where the default spot is at the moment; I keep mine in the same folder as my sketches). Create a new folder named “Log4J” or if you’d like, put in the version numbers. NOTE: The folder MUST have the same name as the JAR file. Within that folder, create a folder named “library” and dump that JAR file in there. After you restart the Processing IDE, you will see a new entry when you go to import a library.

EDIT: I’ve been informed that you can actually just drop the JAR into the sketch folder! That’s very handy. It makes it even easier to integrate Log4J. The only downside to doing this is that if you work with many sketches, you have to remember to drop the JAR into each folder instead of just referencing your library. Thanks to Nacho Cossio for pointing this out.

Use Log4J

Now it’s time to use it! Here is some code that will set up a logger.

String masterPattern = “[%c{1}], %d{HH:mm:ss}, %-5p, {%C}, %m%n”;
fa = new FileAppender();
fa.setName(“Master”);
fa.setFile(sketchPath(“./Logs/” + “Master.log”));
fa.setLayout(new PatternLayout(masterPattern));
fa.setThreshold(Level.DEBUG);
fa.setAppend(false);
fa.activateOptions();
Logger.getRootLogger().addAppender(fa);

This will give you a logger that will dump out everything to file. The “masterPattern” variable holds the format that each log message will have. This specific line of gibberish tells the logger that I want it to look like this:

[categoryName], time(hour:minute:seconds), Priority (if any), {Class name where message was logged from}, message

The category name in my example will be “Master”. I’ve also put commas in there so that I can optionally open the logs in Excel and have it put each value in its own column. This is very handy as you could then use searching and sorting features with zero effort.

Note that in the last line of code, I add the appender to the root logger. Do this only if you want all log messages to go to one file. In my game engine, I’ve set up multiple loggers for different categories to go to different files, and then I use a master logger to consolidate them to one file.

Log Messages

Logger logger = Logger.getLogger("Master");
logger.debug("Log my message");

This will get the logger (which you only need to do once if you store it in a variable) and output a debug message.

There you have it; easy logging for Processing sketches or Java programs. There are likely better and more in-depth tutorials for using Log4J, however I just wanted to give an introduction to get it to pay off quickly without having to browse to nine different sites like I did.

 

Advertisements

Permalink 2 Comments

Impending game demo (by request only)

January 7, 2014 at 1:33 pm (Computer Science, Games, Graphics, JavaScript, Processing, Programming, Video games) (, , , )


So I’m working on getting some levels ready for a demo finally. I need to re-skin the levels to not use *ahem* borrowed art assets before I can do that though. Eventually, I’ll probably post it or public access, but for now it will be released by request only.

Permalink Leave a Comment

New screenshots: 3D Meshes and fire effects

November 30, 2013 at 11:12 am (Games, Graphics, Processing, Programming, Video games) (, , , , , )


Here’s some screenshots I whipped up this morning. It is to show off the fact that I am using 3D meshes for background scene objects. Right now I’m using some objects I got for free from Reiner’s Tiles. Excellent website by the way; great stuff for when you need some basic stock objects or placeholder art (actually the license on this site lets you use it for final commercial projects as well!). ANYWAY, the scene in these shots is a crypt room with some 3D objects. There are some columns and a torch. For the torch I have a basic fire particle effect (it DEFINITELY needs some work though). It has some basic flames and embers with simple behaviour. The second image shows the room rotated at an angle just to prove that I’m using 3D objects.

Room with 3D columns and fire effects

Room with 3D columns and fire effects

Rotated room with 3D columns and fire effects

Rotated room with 3D columns and fire effects

Permalink Leave a Comment

Zombie Mansion: Screenshot

November 17, 2013 at 9:55 pm (Computer Science, Games, Processing, Video games) (, , , , , , )


November 2013 Screenshot

November 2013 Screenshot

Permalink Leave a Comment

Zombie Mansion: Updates and screenshots!

November 13, 2013 at 6:32 pm (Games, Processing, Programming, Video games) (, , , , , , , , )


Yay! Screenshots! I’ve finally had some motivation to post some stuff on my project that isn’t 6 months old. I got a little side tracked with events and stuff, so I’ve been busy and unmotivated. Anyway, I’ve solved the issue I was complaining about in my last post, or at least I have a workaround for it, so it looks nice again. Also, I’ve been using Artisy: Draft for piecing together level designs and other stuff. It makes it a bit easier when I go to make levels in my editor if I have a fancy map telling me where to put stuff.

Anyway, here are some animated GIFs of my “game” right now. Note that they don’t really look right due to the GIF making process I’m using. For example, the animations and movements look really glitchy (and the particle effects die out) because the framerate dies when I record a GIF with the library I’m using. Also, the levels depicted in the GIFs are not finished and polished, so the floors look awkward, etc.

Basic room spin

Basic room spin

Shooting a zombie

Shooting a zombie

Pushing furniture

Pushing furniture

Permalink 2 Comments

Updated Paper Donkey Engine Page

March 19, 2013 at 12:16 pm (Computer Science, Games, Graphics, Processing, Programming) (, , , , , , , , , )


I’ve given the engine description page a facelift. There is now some pretty images and a more up-to-date and polished list of the features.

View it here: Paper Donkey Engine

Permalink Leave a Comment

Paper Donkey Engine: Zombie Mansion Screenshots

February 17, 2013 at 5:17 pm (Computer Science, Games, Graphics, Processing, Programming) (, , , , , , , , )


So I’ve started building an action-adventure-horror game using the new upgrades to the Paper Donkey Engine. If you’ve been following along, I’ve added a physics engine and many other nice features that would support an action game that’s rendered in a 2D-in-3D style using billboards. This weekend I made good use of the built-in scripting engine to make a weapons HUD, shooting, item pick-ups, and a bunch of other things. I’ve added a zombie enemy type that slowly chases the player to try to attack them. The player has a 6-shot revolver to battle the zombies right now and there’s a wide selection of sound effects in the game. Walls and objects can have custom materials assigned so bullet impacts¬†make different noises.

On a minor note, I’ve started making more character art so I can build up a demo that’s a bit more interesting to see. Right now I have 4 directions for the player character and I’m working on walking animations and additional weapons. I have some neat ideas for the game demo that I’m excited to put in as well (storyline and dialogue, etc).

Here’s some new screenshots:

Feb16_2013_A

Room with a movable crate and a zombie to attack the player

Feb17_2013_A

First room in the game demo

Second room in the demo

Second room in the demo

 

Second room in the demo  with the camera rotated

Second room in the demo with the camera rotated

Permalink Leave a Comment

Paper Donkey Game Engine Screenshot update

February 15, 2013 at 9:05 am (Computer Science, Games, Graphics, Processing, Programming) (, , , , , , , , )


So here’s a screenshot I took this morning before leaving for work (I’ll try to get a bigger set of them this weekend). It shows some of the new features, although not all of them are obvious. The biggest new features is the walls that only face forward. This means that you can only see the back walls of the room, and the front ones disappear automatically depending on the camera view. If you rotate the camera around then the scene will fix itself to this effect.

The next feature (which technically isn’t displayed here) is the addition of an NPC system. The second character in the scene is an NPC that you can walk up to and initiate a chat dialogue with. This dialogue system is powered by flexible scripted chat files.

Feb15_2013_A

My next moves will probably be to add AI logic to the NPCs so I can create enemies. I will most likely also import the particle effects I had created for my turn-based game and let the level scripts control them.

Permalink Leave a Comment

Paper Donkey Engine (Feb 2013): Screenshot

February 11, 2013 at 7:42 pm (Computer Science, Games, Graphics, Processing, Programming) (, , , , , , , )


I’ve taken a more recent screenshot of what my game engine can do now. I wrote some code to apply it to an adventure type game where you move from room to room and interact with stuff. It uses Box2D for physics and the Rhino-based Javascript engine from Java for the scripting engine. The blue lines in the screenshot represent the doorways; if you want into them, the level changes to a different room. You can push the crates around and they slide like you’d expect them to (and in this demo, you can click to make a massive number of them). It has the same auto-rotate feature as in my other tech demo/game-in-progress as well. This lets you spin the camera around the focal point by 90 degrees to let you see the level from a different point of view. It’s probably more impressive to see it than to read about it.

 

Feb11_2013_A

 

Next on the to-do list is to add a better input control system. I have some code that will allow players to use XBox 360 controllers as input for this, which should be really neat.

Permalink Leave a Comment

Back on track

October 17, 2012 at 10:15 am (Computer Science, Games, Processing, Programming) (, , , , )


So I’ve finally set my code projects back up. The power supply on my dev box died about a month ago, so I bought a new laptop to fill in while I replaced it (long story). Anyway, now I have my projects running again. Having not seen my game/game engine working in a while, it feels great to see my demo going. It almost makes me think that I could release a full game with it soon. We’ll see though.

I’ve been considering making a couple themed demos just to ensure that all the features I’d need in the future are there. One of the leading ideas for this is a Lord of the Rings Tactics demo. It would feature big scenes such as the Balin’s Tomb skirmish, etc. The idea is to mimic an already well-defined scene so that it’ll be easier when I go to design a full game.

Permalink Leave a Comment

Next page »