User Logging...

Would LogBox, Logger, and/or the Coldspring AOP logging be a good
place to log my user sessions (i.e. - logins, failed logins, logouts,
etc.)? I'd like to collect stuff like the username, date/time, ip
address, etc. Or, is the intended purpose of LogBox (and writing to a
DB table, etc.) more to log application/system events?

LogBox is a great all purpose logging mechanism and you can certainly
use it to log info about your user sessions. You can use it in both
interceptors and handlers, so if you are doing your security checking
through an interception you could autowire your logger in and log
whatever you like like variables.logger.warning("Remote user " &
cgi.remote_addr & " tried to access a secured method without being
logged in"). You could also do the same sort of thing in the handler
which does the actual login/logout routines such as
variables.logger.info("User " & User.getUserName() & " successfully
logged in at " & Now() & ' from ' & cgi.remote_addr)

Is that the sort of info you were looking for?

Judah

Thanks Judah, that totally helps. That would work really well for an
admin reviewing a log file to see what's happened, but what if you
wanted to store all the data in separate columns in the database? As
an example, imagine you wanted an admin to be able to look up all
logins for a a specific user to see if they have been using their
subscription? Like an activity page that gets all logins, attempts,
etc.by username or user id. Would you still start with LogBox?

Thanks again,
Thomas

I'd be inclined to try to do it in an interceptor with a mix of
interception points (onLoginAttempt, onSessionEnd, etc.).

You can certainly do that, no problems. LogBox supports a notion of
different appenders. An appender is simply a way of rendering your
logging output. I think that by default the example install configures
LogBox with the AsyncRollingFileAppender and TraceAppender. The
AsyncRollingFileAppender writes log messages asynchronouslyl to a log
file that rolls over after it reaches a certain size. The
TraceAppender logs messages to the debug area on the screen in your CB
app. If you have both appenders configured, a single log message
logger.info("This is some info") will then be written to both the log
file on your drive and to the debug trace appender area in your
rendered page display.

LogBox already comes with an number of built-in appenders, one of
which is called DBAppender for writing data to a table. I have not
used it before but it says it will even create the log table for you.
If that setup is sufficient, then you can just add the DBAppender to
your logging setup and, voila, it will log your entries to the db as
well as to any other appenders you have set up. If the way it does the
logging doesn't quite fit your needs, you can write your own Appender
and have it log your data in a custom format that does suit your
needs.

The various appenders and what you'd need to write you own are
documented here:
http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbLogBox

Cheers,
Judah

The DBAppender is actually what I was originally looking at. The only place I’ve found for actually using it is the DBAppender.cfc itself. The documentation (http://blog.coldboxframework.com/post.cfm/logbox-enterprise-coldfusion-logging-library-released) is great for the general info, but it’s a little overwhelming for me when there are no examples. I would love to see some examples of how to use LogBox/Logger outside of the basic console and file appenders :wink:

It makes me more inclined to use a strategy like what Jason posted. For instance, the built in DB logging looks like (see below) it requires specific columns… and those columns don’t fit my needs.

Properties:

  • dsn : the dsn to use for logging
  • table : the table to store the logs in
  • columnMap : A column map for aliasing columns. (Optional)
  • autocreate : if true, then we will create the table. Defaults to false (Optional)
  • ensureChecks : if true, then we will check the dsn and table existence. Defaults to true (Optional)
  • textDBType : Defaults to ‘text’. This is used on the autocreate features of the appender for the message and extended info fields. This is the actual database type.

The columns needed in the table are

  • id : UUID
  • severity : string
  • category : string
  • logdate : timestamp
  • appendername : string
  • message : string
  • extrainfo : string

Doh... I just clicked on the link to the LogBox docs, and I see the
DBAppender info is in there.

- Thomas

HE,

Reading pays off!!

I will be adding more samples to logbox as we continue to migrate the docs to the new wiki, which has about 85% completion now.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com