diff src/implab/log/_LogMixin.js @ 2:7d7059d2a810

Подправлены пути в пакетах
author egor
date Fri, 02 Jun 2017 19:28:20 +0300
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/implab/log/_LogMixin.js	Fri Jun 02 19:28:20 2017 +0300
@@ -0,0 +1,67 @@
+define([ "dojo/_base/declare" ],
+
+function(declare) {
+    var cls = declare(null, {
+        _logChannel : null,
+
+        _logLevel : 1,
+
+        constructor : function(opts) {
+            if (typeof opts == "object") {
+                if ("logChannel" in opts)
+                    this._logChannel = opts.logChannel;
+                if ("logLevel" in opts)
+                    this._logLevel = opts.logLevel;
+            }
+        },
+
+        getLogChannel : function() {
+            return this._logChannel;
+        },
+
+        setLogChannel : function(v) {
+            this._logChannel = v;
+        },
+
+        getLogLevel : function() {
+            return this._logLevel;
+        },
+
+        setLogLevel : function(v) {
+            this._logLevel = v;
+        },
+
+        log : function(format) {
+            if (this._logChannel && this._logLevel > 2)
+                this._logChannel.log.apply(this._logChannel, arguments);
+        },
+        warn : function(format) {
+            if (this._logChannel && this._logLevel > 1)
+                this._logChannel.warn.apply(this._logChannel, arguments);
+        },
+        error : function(format) {
+            if (this._logChannel && this._logLevel > 0)
+                this._logChannel.error.apply(this._logChannel, arguments);
+        },
+
+        /**
+         * Used to by widgets
+         */
+        startup : function() {
+            var me = this, parent;
+            if (!me.getLogChannel()) {
+                parent = me;
+                while (parent = parent.getParent()) {
+                    if (parent.getLogChannel) {
+                        me.setLogChannel(parent.getLogChannel());
+                        if(parent.getLogLevel)
+                            me.setLogLevel(parent.getLogLevel());
+                        break;
+                    }
+                }
+            }
+            this.inherited(arguments);
+        }
+    });
+    return cls;
+});
\ No newline at end of file