Commits

Robert Clipsham committed 0c325a8

Add logging support for models.

  • Participants
  • Parent commits 3eb88ab

Comments (0)

Files changed (1)

  */
 module serenity.Model;
 
+import serenity.Log;
+
 public import serenity.Database : Result;
 public import serenity.SqlQuery;
 
 abstract class Model
 {
+    private Logger mLog;
+
+    /**
+     * Return the logger for the current model
+     *
+     * Examples:
+     * ----
+     *  void myMethod()
+     *  {
+     *      if (log.info) log.info("myMethod()");
+     *  }
+     * ----
+     * Returns:
+     *  Instance of Logger for the current model
+     */
+    protected Logger log()
+    {
+        if (mLog is null)
+        {
+            mLog = Log.getLogger(this.classinfo.name);
+        }
+        return mLog;
+    }
+
     abstract public void create();
 }