early es6 test class for Dragonfly

This commit is contained in:
斟酌 鵬兄 2015-10-19 18:50:17 +08:00
parent 0fcbbea2fa
commit fe801aaa49

View File

@ -1,3 +1,4 @@
"use strict";
var util = require( "util" ); var util = require( "util" );
/*{{{ Private methods */ /*{{{ Private methods */
@ -22,7 +23,44 @@ function logDate( date )
} }
/*}}}*/ /*}}}*/
// Logger // Logger
function Dragonfly( logHandler ) class Dragonfly
{
// Static properties
static get defaultSphere()
{
return this.__dsphere;
}
static set defaultSphere( v )
{
return this.__dsphere = Math.floor( v + 0 );
}
static get Spheres()
{
return {
// Debug
THERMO: 30
// Inspect
, STRATO: 20
// Production
, HYDRO: 10
, LITHO: 0
};
}
static get Visibility()
{
return {
VISIBLE: 9
, VH8: 8, VH7: 7, VH6: 6
, HIDDEN: 5
, HU4: 4, HU3: 3, HU2: 2
, UNSEEN: 1
};
}
constructor( logHandler )
{ {
this.currentSphere = Dragonfly.defaultSphere; this.currentSphere = Dragonfly.defaultSphere;
this.Visibility = Dragonfly.Visibility; this.Visibility = Dragonfly.Visibility;
@ -58,27 +96,27 @@ function Dragonfly( logHandler )
this.Info( "Dragonfly ready.", Dragonfly.Visibility.VISIBLE ); this.Info( "Dragonfly ready.", Dragonfly.Visibility.VISIBLE );
} }
Dragonfly.prototype.Debug = function( mesg, visibility ) Debug( mesg, visibility )
{ {
this.Log( mesg, Dragonfly.Spheres.THERMO, visibility ); this.Log( mesg, Dragonfly.Spheres.THERMO, visibility );
}; }
Dragonfly.prototype.Info = function( mesg, visibility ) Info( mesg, visibility )
{ {
this.Log( mesg, Dragonfly.Spheres.STRATO, visibility ); this.Log( mesg, Dragonfly.Spheres.STRATO, visibility );
}; }
Dragonfly.prototype.Warning = function( mesg, visibility ) Warning( mesg, visibility )
{ {
this.Log( mesg, Dragonfly.Spheres.HYDRO, visibility ); this.Log( mesg, Dragonfly.Spheres.HYDRO, visibility );
}; }
Dragonfly.prototype.Error = function( mesg, visibility ) Error( mesg, visibility )
{ {
this.Log( mesg, Dragonfly.Spheres.LITHO, visibility ); this.Log( mesg, Dragonfly.Spheres.LITHO, visibility );
}; }
Dragonfly.prototype.Log = function( mesg, sphere, visibility ) Log( mesg, sphere, visibility )
{ {
if( isNaN( sphere ) ) sphere = Dragonfly.Spheres.LITHO; if( isNaN( sphere ) ) sphere = Dragonfly.Spheres.LITHO;
@ -100,9 +138,9 @@ Dragonfly.prototype.Log = function( mesg, sphere, visibility )
: this.writeLine( mesg ) : this.writeLine( mesg )
; ;
} }
}; }
Dragonfly.prototype.writeLine = function () writeLine ()
{ {
for( var i in arguments ) for( var i in arguments )
{ {
@ -119,32 +157,14 @@ Dragonfly.prototype.writeLine = function ()
} }
} }
} }
}; }
Dragonfly.prototype.__log = function ( line ) __log ( line )
{ {
this.logHandler.write( this.ptag + logDate( new Date() ) + util.format( line ) + "\n" ); this.logHandler.write( this.ptag + logDate( new Date() ) + util.format( line ) + "\n" );
}; }
}
// Static properties
Dragonfly.defaultSphere = 10; Dragonfly.defaultSphere = 10;
Dragonfly.Spheres = {
// Debug
THERMO: 30
// Inspect
, STRATO: 20
// Production
, HYDRO: 10
, LITHO: 0
};
Dragonfly.Visibility = {
VISIBLE: 9
, VH8: 8, VH7: 7, VH6: 6
, HIDDEN: 5
, HU4: 4, HU3: 3, HU2: 2
, UNSEEN: 1
};
module.exports = Dragonfly; module.exports = Dragonfly;