Loggly 支持非英语字符

发布于 2025-01-07 11:08:08 字数 342 浏览 0 评论 0原文

我正在尝试将我的网络应用程序收集的数据记录到 Loggly。但是,在提交包含俄语或希伯来语字符串的 JSON(甚至纯文本)后,我在输出中收到问号。

包含俄语单词的示例字符串:

curl -H "content-type:text/plain" -d "Привет, мир!" https://logs.loggly.com/inputs/YOUR-INPUT-GOES-HERE

Loggly 中是否支持非英语字符?如果是,我该如何使用它?我很确定我正在以 UTF-8 格式发送数据。

I'm trying to log data, collected by my web application to Loggly. However after submitting JSON (or even plain text) containing strings in russian or hebrew I receive question marks at output.

Example string that contains word in russian:

curl -H "content-type:text/plain" -d "Привет, мир!" https://logs.loggly.com/inputs/YOUR-INPUT-GOES-HERE

Is there support for non-english characters in Loggly? If yes, how do I utilize it? I'm pretty sure I'm sending data as UTF-8.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暖树树初阳… 2025-01-14 11:08:08

显然令人惊讶的是,似乎只支持 ASCII (0-127) 字符:

我们仅索引 ASCII 和属于 ASCII 的 UTF-8(如果它们不属于这两个类别,则数据将显示为?)。对于给您带来的不便,我深表歉意。

来源:http://community.loggly.com/customer /portal/questions/6549048-cyrrilic-encoding?b_id=50

Apparently and surprisingly, it seems that only ASCII (0-127) chars are supported:

We only index ASCII and UTF-8 which falls into ASCII (If they don't fall into these two categories the data will be displayed as ?'s). My apologies for the inconvenience.

Source: http://community.loggly.com/customer/portal/questions/6549048-cyrrilic-encoding?b_id=50

囍孤女 2025-01-14 11:08:08

我自己还没有使用过 loggly,所以这只是一个疯狂的猜测:需要指定内容类型标头中的字符集:

Content-Type: text/plain; charset=utf-8

否则它可能默认为 ascii。

Have not used loggly myself yet, so this is just a wild guess: The charset in the content-type header needs to be specified:

Content-Type: text/plain; charset=utf-8

Otherwise it probably defaults to ascii.

﹉夏雨初晴づ 2025-01-14 11:08:08

查看这个问题的解决方案。

import { Injectable } from '@angular/core';

@Injectable()
export class Loggly {
  private LTracker: any;

  constructor() {

    this.LTracker = this.LTrack(window, document) || [];
    this.LTracker.push({
      'logglyKey': 'YOUR_KEY_HERE',
      'sendConsoleErrors' : true,
      'tag' : 'loggly-jslogger'
    });
  }

  push(props) {
    this.LTracker.push(props);
  }

  LTrack (window, document) {
    var LOGGLY_INPUT_PREFIX = 'http' + (('https:' === document.location.protocol ? 's' : '')) + '://',
      LOGGLY_COLLECTOR_DOMAIN = 'logs-01.loggly.com',
      LOGGLY_SESSION_KEY = 'logglytrackingsession',
      LOGGLY_SESSION_KEY_LENGTH = LOGGLY_SESSION_KEY.length + 1,
      LOGGLY_PROXY_DOMAIN = 'loggly';

    function uuid() {
      // lifted from here -> http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
      });
    }

    function LogglyTracker() {
      this.key = false;
      this.sendConsoleErrors = false;
      this.tag = 'jslogger';
      this.useDomainProxy = false;
    }

    function setKey(tracker, key) {
      tracker.key = key;
      tracker.setSession();
      setInputUrl(tracker);
    }

    function setTag(tracker, tag) {
      tracker.tag = tag;
    }

    function setDomainProxy(tracker, useDomainProxy) {
      tracker.useDomainProxy = useDomainProxy;
      //refresh inputUrl value
      setInputUrl(tracker);
    }

    function setSendConsoleError(tracker, sendConsoleErrors) {
      tracker.sendConsoleErrors = sendConsoleErrors;

      if (tracker.sendConsoleErrors === true) {
        var _onerror = window.onerror;
        //send console error messages to Loggly
        window.onerror = function (msg, url, line, col, err){
          tracker.push({
            category: 'BrowserJsException',
            exception: {
              message: msg,
              url: url,
              lineno: line,
              colno: col,
              stack: err ? err.stack : 'n/a',
            }
          });

          if (_onerror && typeof _onerror === 'function') {
            _onerror.apply(window, arguments);
          }
        };
      }
    }

    function setInputUrl(tracker) {

      if (tracker.useDomainProxy == true) {
        tracker.inputUrl = LOGGLY_INPUT_PREFIX
          + window.location.host
          + '/'
          + LOGGLY_PROXY_DOMAIN
          + '/inputs/'
          + tracker.key
          + '/tag/'
          + tracker.tag;
      }
      else {
        tracker.inputUrl = LOGGLY_INPUT_PREFIX
          + (tracker.logglyCollectorDomain || LOGGLY_COLLECTOR_DOMAIN)
          + '/inputs/'
          + tracker.key
          + '/tag/'
          + tracker.tag;
      }
    }

    LogglyTracker.prototype = {
      setSession: function (session_id) {
        if (session_id) {
          this.session_id = session_id;
          this.setCookie(this.session_id);
        } else if (!this.session_id) {
          this.session_id = this.readCookie();
          if (!this.session_id) {
            this.session_id = uuid();
            this.setCookie(this.session_id);
          }
        }
      },
      push: function (data) {
        var type = typeof data;

        if (!data || !(type === 'object' || type === 'string')) {
          return;
        }

        var self = this;


        if (type === 'string') {
          data = {
            'text': data
          };
        } else {
          if (data.logglyCollectorDomain) {
            self.logglyCollectorDomain = data.logglyCollectorDomain;
            return;
          }

          if (data.sendConsoleErrors !== undefined) {
            setSendConsoleError(self, data.sendConsoleErrors);
          }

          if (data.tag) {
            setTag(self, data.tag);
          }

          if (data.useDomainProxy) {
            setDomainProxy(self, data.useDomainProxy);
          }

          if (data.logglyKey) {
            setKey(self, data.logglyKey);
            return;
          }

          if (data.session_id) {
            self.setSession(data.session_id);
            return;
          }
        }

        if (!self.key) {
          return;
        }

        self.track(data);


      },
      track: function (data) {
        // inject session id
        data.sessionId = this.session_id;

        try {
          //creating an asynchronous XMLHttpRequest
          var xmlHttp = new XMLHttpRequest();
          xmlHttp.open('POST', this.inputUrl, true); //true for asynchronous request
          xmlHttp.setRequestHeader('Content-Type', 'text/plain; charset=utf-8');
          xmlHttp.send(JSON.stringify(data));

        } catch (ex) {
          if (window && window.console && typeof window.console.log === 'function') {
            console.log("Failed to log to loggly because of this exception:\n" + ex);
            console.log("Failed log data:", data);
          }
        }
      },
      /**
       *  These cookie functions are not a global utilities.  It is for purpose of this tracker only
       */
      readCookie: function () {
        var cookie = document.cookie,
          i = cookie.indexOf(LOGGLY_SESSION_KEY);
        if (i < 0) {
          return false;
        } else {
          var end = cookie.indexOf(';', i + 1);
          end = end < 0 ? cookie.length : end;
          return cookie.slice(i + LOGGLY_SESSION_KEY_LENGTH, end);
        }
      },
      setCookie: function (value) {
        document.cookie = LOGGLY_SESSION_KEY + '=' + value;
      }
    };

    var existing = window._LTracker;

    var tracker = new LogglyTracker();

    if (existing && existing.length) {
      var i = 0,
        eLength = existing.length;
      for (i = 0; i < eLength; i++) {
        tracker.push(existing[i]);
      }
    }

     return tracker;
  };
}

check out this solution to the problem.

import { Injectable } from '@angular/core';

@Injectable()
export class Loggly {
  private LTracker: any;

  constructor() {

    this.LTracker = this.LTrack(window, document) || [];
    this.LTracker.push({
      'logglyKey': 'YOUR_KEY_HERE',
      'sendConsoleErrors' : true,
      'tag' : 'loggly-jslogger'
    });
  }

  push(props) {
    this.LTracker.push(props);
  }

  LTrack (window, document) {
    var LOGGLY_INPUT_PREFIX = 'http' + (('https:' === document.location.protocol ? 's' : '')) + '://',
      LOGGLY_COLLECTOR_DOMAIN = 'logs-01.loggly.com',
      LOGGLY_SESSION_KEY = 'logglytrackingsession',
      LOGGLY_SESSION_KEY_LENGTH = LOGGLY_SESSION_KEY.length + 1,
      LOGGLY_PROXY_DOMAIN = 'loggly';

    function uuid() {
      // lifted from here -> http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
      });
    }

    function LogglyTracker() {
      this.key = false;
      this.sendConsoleErrors = false;
      this.tag = 'jslogger';
      this.useDomainProxy = false;
    }

    function setKey(tracker, key) {
      tracker.key = key;
      tracker.setSession();
      setInputUrl(tracker);
    }

    function setTag(tracker, tag) {
      tracker.tag = tag;
    }

    function setDomainProxy(tracker, useDomainProxy) {
      tracker.useDomainProxy = useDomainProxy;
      //refresh inputUrl value
      setInputUrl(tracker);
    }

    function setSendConsoleError(tracker, sendConsoleErrors) {
      tracker.sendConsoleErrors = sendConsoleErrors;

      if (tracker.sendConsoleErrors === true) {
        var _onerror = window.onerror;
        //send console error messages to Loggly
        window.onerror = function (msg, url, line, col, err){
          tracker.push({
            category: 'BrowserJsException',
            exception: {
              message: msg,
              url: url,
              lineno: line,
              colno: col,
              stack: err ? err.stack : 'n/a',
            }
          });

          if (_onerror && typeof _onerror === 'function') {
            _onerror.apply(window, arguments);
          }
        };
      }
    }

    function setInputUrl(tracker) {

      if (tracker.useDomainProxy == true) {
        tracker.inputUrl = LOGGLY_INPUT_PREFIX
          + window.location.host
          + '/'
          + LOGGLY_PROXY_DOMAIN
          + '/inputs/'
          + tracker.key
          + '/tag/'
          + tracker.tag;
      }
      else {
        tracker.inputUrl = LOGGLY_INPUT_PREFIX
          + (tracker.logglyCollectorDomain || LOGGLY_COLLECTOR_DOMAIN)
          + '/inputs/'
          + tracker.key
          + '/tag/'
          + tracker.tag;
      }
    }

    LogglyTracker.prototype = {
      setSession: function (session_id) {
        if (session_id) {
          this.session_id = session_id;
          this.setCookie(this.session_id);
        } else if (!this.session_id) {
          this.session_id = this.readCookie();
          if (!this.session_id) {
            this.session_id = uuid();
            this.setCookie(this.session_id);
          }
        }
      },
      push: function (data) {
        var type = typeof data;

        if (!data || !(type === 'object' || type === 'string')) {
          return;
        }

        var self = this;


        if (type === 'string') {
          data = {
            'text': data
          };
        } else {
          if (data.logglyCollectorDomain) {
            self.logglyCollectorDomain = data.logglyCollectorDomain;
            return;
          }

          if (data.sendConsoleErrors !== undefined) {
            setSendConsoleError(self, data.sendConsoleErrors);
          }

          if (data.tag) {
            setTag(self, data.tag);
          }

          if (data.useDomainProxy) {
            setDomainProxy(self, data.useDomainProxy);
          }

          if (data.logglyKey) {
            setKey(self, data.logglyKey);
            return;
          }

          if (data.session_id) {
            self.setSession(data.session_id);
            return;
          }
        }

        if (!self.key) {
          return;
        }

        self.track(data);


      },
      track: function (data) {
        // inject session id
        data.sessionId = this.session_id;

        try {
          //creating an asynchronous XMLHttpRequest
          var xmlHttp = new XMLHttpRequest();
          xmlHttp.open('POST', this.inputUrl, true); //true for asynchronous request
          xmlHttp.setRequestHeader('Content-Type', 'text/plain; charset=utf-8');
          xmlHttp.send(JSON.stringify(data));

        } catch (ex) {
          if (window && window.console && typeof window.console.log === 'function') {
            console.log("Failed to log to loggly because of this exception:\n" + ex);
            console.log("Failed log data:", data);
          }
        }
      },
      /**
       *  These cookie functions are not a global utilities.  It is for purpose of this tracker only
       */
      readCookie: function () {
        var cookie = document.cookie,
          i = cookie.indexOf(LOGGLY_SESSION_KEY);
        if (i < 0) {
          return false;
        } else {
          var end = cookie.indexOf(';', i + 1);
          end = end < 0 ? cookie.length : end;
          return cookie.slice(i + LOGGLY_SESSION_KEY_LENGTH, end);
        }
      },
      setCookie: function (value) {
        document.cookie = LOGGLY_SESSION_KEY + '=' + value;
      }
    };

    var existing = window._LTracker;

    var tracker = new LogglyTracker();

    if (existing && existing.length) {
      var i = 0,
        eLength = existing.length;
      for (i = 0; i < eLength; i++) {
        tracker.push(existing[i]);
      }
    }

     return tracker;
  };
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文