11/// <reference path="../references.ts" />
22
33module Exceptionless {
4- export class Configuration {
4+ export class Configuration implements IConfigurationSettings {
55 private _apiKey :string ;
66 private _enabled :boolean = false ;
77 private _serverUrl :string = 'https://collector.exceptionless.io' ;
88 private _plugins :IEventPlugin [ ] = [ ] ;
99
1010 public lastReferenceIdManager :ILastReferenceIdManager = new InMemoryLastReferenceIdManager ( ) ;
11- public log :ILog = new NullLog ( ) ;
12- public submissionBatchSize = 50 ;
13- public submissionClient :ISubmissionClient = new DefaultSubmissionClient ( ) ;
14- public storage :IStorage < any > = new InMemoryStorage < any > ( ) ;
11+ public log :ILog ;
12+ public submissionBatchSize ;
13+ public submissionClient :ISubmissionClient ;
14+ public storage :IStorage < any > ;
1515 public queue :IEventQueue ;
1616 public defaultTags :string [ ] = [ ] ;
1717 public defaultData :Object = { } ;
1818
19- constructor ( apiKey :string , serverUrl ?:string ) {
20- this . apiKey = apiKey ;
21- this . serverUrl = serverUrl ;
22- this . queue = new DefaultEventQueue ( this ) ;
19+ constructor ( settings ?:IConfigurationSettings ) {
20+ function inject ( fn :any ) {
21+ return typeof fn === 'function' ? fn ( this ) : fn ;
22+ }
23+
24+ settings = Utils . merge ( Configuration . defaults , settings ) ;
25+
26+ this . apiKey = settings . apiKey ;
27+ this . serverUrl = settings . serverUrl ;
28+ this . lastReferenceIdManager = inject ( settings . lastReferenceIdManager ) || new InMemoryLastReferenceIdManager ( ) ;
29+ this . log = inject ( settings . log ) || new NullLog ( ) ;
30+ this . submissionBatchSize = inject ( settings . submissionBatchSize ) || 50 ;
31+ this . submissionClient = inject ( settings . submissionClient ) || new DefaultSubmissionClient ( ) ;
32+ this . storage = inject ( settings . storage ) || new InMemoryStorage < any > ( ) ;
33+ this . queue = inject ( settings . queue ) || new DefaultEventQueue ( this ) ;
2334
2435 EventPluginManager . addDefaultPlugins ( this ) ;
2536 }
@@ -29,7 +40,7 @@ module Exceptionless {
2940 }
3041
3142 public set apiKey ( value :string ) {
32- this . _apiKey = value ;
43+ this . _apiKey = value || null ;
3344 this . _enabled = ! ! value && value . length > 0 ;
3445 }
3546
@@ -103,5 +114,14 @@ module Exceptionless {
103114 public useReferenceIds ( ) : void {
104115 this . addPlugin ( new ReferenceIdPlugin ( ) ) ;
105116 }
117+
118+ private static _defaultSettings :IConfigurationSettings = null ;
119+ public static get defaults ( ) {
120+ if ( Configuration . _defaultSettings === null ) {
121+ Configuration . _defaultSettings = { } ;
122+ }
123+
124+ return Configuration . _defaultSettings ;
125+ }
106126 }
107127}
0 commit comments