123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- /*
- * Copyright (C) 2016 Bilibili. All Rights Reserved.
- *
- * @author zheng qian <xqq@xqq.im>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import EventEmitter from 'events';
- class Log {
- static e(tag, msg) {
- if (!tag || Log.FORCE_GLOBAL_TAG)
- tag = Log.GLOBAL_TAG;
- let str = `[${tag}] > ${msg}`;
- if (Log.ENABLE_CALLBACK) {
- Log.emitter.emit('log', 'error', str);
- }
- if (!Log.ENABLE_ERROR) {
- return;
- }
- if (console.error) {
- console.error(str);
- } else if (console.warn) {
- console.warn(str);
- } else {
- console.log(str);
- }
- }
- static i(tag, msg) {
- if (!tag || Log.FORCE_GLOBAL_TAG)
- tag = Log.GLOBAL_TAG;
- let str = `[${tag}] > ${msg}`;
- if (Log.ENABLE_CALLBACK) {
- Log.emitter.emit('log', 'info', str);
- }
- if (!Log.ENABLE_INFO) {
- return;
- }
- if (console.info) {
- console.info(str);
- } else {
- console.log(str);
- }
- }
- static w(tag, msg) {
- if (!tag || Log.FORCE_GLOBAL_TAG)
- tag = Log.GLOBAL_TAG;
- let str = `[${tag}] > ${msg}`;
- if (Log.ENABLE_CALLBACK) {
- Log.emitter.emit('log', 'warn', str);
- }
- if (!Log.ENABLE_WARN) {
- return;
- }
- if (console.warn) {
- console.warn(str);
- } else {
- console.log(str);
- }
- }
- static d(tag, msg) {
- if (!tag || Log.FORCE_GLOBAL_TAG)
- tag = Log.GLOBAL_TAG;
- let str = `[${tag}] > ${msg}`;
- if (Log.ENABLE_CALLBACK) {
- Log.emitter.emit('log', 'debug', str);
- }
- if (!Log.ENABLE_DEBUG) {
- return;
- }
- if (console.debug) {
- console.debug(str);
- } else {
- console.log(str);
- }
- }
- static v(tag, msg) {
- if (!tag || Log.FORCE_GLOBAL_TAG)
- tag = Log.GLOBAL_TAG;
- let str = `[${tag}] > ${msg}`;
- if (Log.ENABLE_CALLBACK) {
- Log.emitter.emit('log', 'verbose', str);
- }
- if (!Log.ENABLE_VERBOSE) {
- return;
- }
- console.log(str);
- }
- }
- Log.GLOBAL_TAG = 'flv.js';
- Log.FORCE_GLOBAL_TAG = false;
- Log.ENABLE_ERROR = true;
- Log.ENABLE_INFO = true;
- Log.ENABLE_WARN = true;
- Log.ENABLE_DEBUG = true;
- Log.ENABLE_VERBOSE = true;
- Log.ENABLE_CALLBACK = false;
- Log.emitter = new EventEmitter();
- export default Log;
|