当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript log-cool.logInfo函数代码示例

本文整理汇总了TypeScript中log-cool.logInfo函数的典型用法代码示例。如果您正苦于以下问题:TypeScript logInfo函数的具体用法?TypeScript logInfo怎么用?TypeScript logInfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了logInfo函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: init

/**
 * Init app
 */
async function init(): Promise<State> {
	console.log('Welcome to Misskey!\n');

	console.log(chalk.bold('Misskey Core <aoi>'));

	let warn = false;

	// Get commit info
	const commit = await prominence(git).getLastCommit();
	console.log(`commit: ${commit.shortHash} ${commit.author.name} <${commit.author.email}>`);
	console.log(`        ${new Date(parseInt(commit.committedOn, 10) * 1000)}`);

	console.log('\nInitializing...\n');

	if (IS_DEBUG) {
		logWarn('It is not in the Production mode. Do not use in the Production environment.');
	}

	logInfo(`environment: ${env}`);

	// Get machine info
	const totalmem = (os.totalmem() / 1024 / 1024 / 1024).toFixed(1);
	const freemem = (os.freemem() / 1024 / 1024 / 1024).toFixed(1);
	logInfo(`MACHINE: ${os.hostname()}`);
	logInfo(`MACHINE: CPU: ${os.cpus().length}core`);
	logInfo(`MACHINE: MEM: ${totalmem}GB (available: ${freemem}GB)`);

	if (!fs.existsSync(require('./config').configPath)) {
		logFailed('Configuration not found');
		return State.failed;
	}

	// Load config
	const conf = require('./config').default;

	logDone('Success to load configuration');
	logInfo(`maintainer: ${conf.maintainer}`);

	checkDependencies();

	// Check if a port is being used
	if (await portUsed.check(conf.port)) {
		logFailed(`Port: ${conf.port} is already used!`);
		return State.failed;
	}

	// Try to connect to MongoDB
	try {
		await initdb(conf);
		logDone('Success to connect to MongoDB');
	} catch (e) {
		logFailed(`MongoDB: ${e}`);
		return State.failed;
	}

	return warn ? State.warn : State.success;
}
开发者ID:syuilo,项目名称:misskey-core,代码行数:60,代码来源:index.ts

示例2: logInfo

			socket.on('disconnect', (reason: string) => {
				logInfo(`Diconnect Socket.IO stream: /streaming/${name} by ${reason}`);
				// ハンドラを削除
				connections[endpoint].removeListener('error', upstreamErrorEventHandler);
				connections[endpoint].removeListener('close', upstreamCloseEventHandler);
				connections[endpoint].removeListener('message', upstreamMessageEventHandler);
				// 誰からも利用されていないようならコネクションを削除
				if (1 > --connectedCounts[endpoint]) {
					connections[endpoint].close();
				}
			});
开发者ID:sagume,项目名称:Misskey-Web,代码行数:11,代码来源:index.ts

示例3: checkDependency

function checkDependency(serviceName: string, command: string, transform: (x: string) => string): void {
	const code = {
		success: 0,
		notFound: 127
	};
	const x = exec(command, { silent: true }) as any;
	if (x.code === code.success) {
		logInfo(`DEPS: ${serviceName} ${transform(x.stdout)}`);
	} else if (x.code === code.notFound) {
		logWarn(`Unable to find ${serviceName}`);
	}
}
开发者ID:syuilo,项目名称:misskey-core,代码行数:12,代码来源:check-dependencies.ts

示例4: checkDependency

function checkDependency(serviceName: string, command: string, transform: (x: string) => string): void {
	try {
		const x = execSync(command, { stdio: ['pipe', 'pipe', 'ignore'] });
		const ver = transform(x.toString());
		if (ver !== null) {
			logInfo(`${serviceName} ${ver}`);
		} else {
			logWarn(`Check dependencies error (${serviceName})`);
			logWarn(`Regexp used for version check of ${serviceName} is probably messed up`);
		}
	} catch (e) {
		logWarn(`Unable to find (${serviceName})`);
	}
}
开发者ID:Tosuke,项目名称:Misskey-API,代码行数:14,代码来源:check-dependencies.ts

示例5: function

export default function(): void {
	logInfo(`(cluster: ${cluster.worker.id}) Initializing server`);

	const server = new hapi.Server();
	server.connection({ port: config.port.http });

	endpoints.forEach(endpoint => {
		if (endpoint.name === 'album/files/upload') {
			server.route({
				method: 'post',
				path: `/${endpoint.name}`,
				config: {
					payload: {
						output: 'file',
						parse: true,
						maxBytes: dataSize.fromMiB(100),
						allow: 'multipart/form-data'
					},
					handler: (request: any, reply: any): void => {
						apiHandler(endpoint, request, reply);
					}
				}
			});
		} else {
			server.route({
				method: 'post',
				path: `/${endpoint.name}`,
				handler: (request: any, reply: any): void => {
					apiHandler(endpoint, request, reply);
				}
			});
		}
	});

	server.route({ method: '*', path: '/{p*}', handler: notFoundHandler });

	server.start(() => {
		logInfo(`(cluster: ${cluster.worker.id}) Listening at ${server.info.uri}`);
	});
}
开发者ID:akionux,项目名称:Misskey-API,代码行数:40,代码来源:server.ts

示例6: function

export default async function(name: string, ws: Websocket, req: http.IncomingMessage): Promise<void> {
	logInfo(`Request: stream /streams/${name}`);

	const query: { [key: string]: string|string[] } = query_process.parse(url_process.parse(req.url).query);

	const reject = (mes: string = 'authentication failed') => {
		const res = {
			type: 'error',
			value: {
				message: mes
			}
		};
		ws.send(JSON.stringify(res));
		ws.close();
	};

	if (query['passkey'] === undefined || query['passkey'] === null) {
		reject("'passkey' is required");
		return;
	}
	if (query['user-id'] === undefined || query['user-id'] === null) {
		reject("'user-id' is required");
		return;
	}
	if (!isValidApiKey(query['passkey'] as string)) {
		reject("'passkey' is not a valid api key");
		return;
	}

	const user = await getUserByID(query['user-id'] as string);
	if (user === null) {
		reject('user not found');
		return;
	}

	const handler = require(`./stream-handlers/${name}`).default;
	handler(user, ws, query);
}
开发者ID:Tosuke,项目名称:Misskey-API,代码行数:38,代码来源:stream-handler.ts

示例7: async

		io.of(`/streaming/${name}`).on('connect', async (socket: SocketIO.Socket) => {
			logInfo(`Request Socket.IO stream: /streaming/${name}`);
			// クッキーが無い場合切断
			if (!socket.handshake.headers.cookie) {
				emitter(socket, 'announcement', {
					type: 'error',
					message: `cookie doesn't exist`,
					happen: 'proxy'
				}, true);
				return;
			}
			const cookies: { [key: string]: string } = cookie.parse(socket.handshake.headers.cookie);
			// cookieに必要情報が無い場合切断
			if (!cookies[config.sessionKey] && ! /s:(.+?)\./.test(cookies[config.sessionKey])) {
				emitter(socket, 'announcement', {
					type: 'error',
					message: `cookie ${config.sessionKey} doesn't exist`,
					happen: 'proxy'
				}, true);
				return;
			}
			const sessionKey: string = cookies[config.sessionKey].match(/s:(.+?)\./)[1];
			let session: any;
			try {
				session = await sessionGetter(sessionKey);
			} catch (e) {
				// セッション取ってこれなかったら切断
				emitter(socket, 'announcement', {
					type: 'error',
					message: `session doesn't exist`,
					happen: 'proxy'
				}, true);
				return;
			}

			// 接続URL組み立て
			const endpoint: string = (() => {
				const base = `ws://${config.apiServerIp}:${config.apiServerPort}/streams/${name}?passkey=${config.apiPasskey}`;
				switch (name) {
					case 'talk': return `${base}&user-id=${session.userId}&otherparty-id=${socket.handshake.query['otherparty-id']}`;
					case 'group-talk': return `${base}&user-id=${session.userId}&otherparty-id=${socket.handshake.query['group-id']}`;
					default: return `${base}&user-id=${session.userId}`;
				}
			})();

			if (!(endpoint in connections)) {
				try {
					logInfo(`Connect upstream WebSocket stream: ${name} w/ user-id ${session.userId}`);
					// APIに接続
					connections[endpoint] = await connector(endpoint);
					// クローズ時に connections[endpoint] を削除する
					connections[endpoint].on('close', () => {
						logInfo(`Close upstream WebSocket stream: ${name} w/ user-id ${session.userId}`);
						delete connections[endpoint];
					});
				} catch (e) {
					emitter(socket, 'announcement', {
						type: 'error',
						message: `can't establish connection`,
						detail: e.toString(),
						happen: 'upstream'
					}, true);
					throw e;
				}
			}
			// connection に対してどれだけのクライアントがぶら下がっているかを記録
			if (!(endpoint in connectedCounts)) {
				connectedCounts[endpoint] = 0;
			}
			++connectedCounts[endpoint];

			/**
			 * ハンドラ生成・登録
			 */
			// なんらかのエラー
			const upstreamErrorEventHandler = (error: Error) => {
				emitter(socket, 'announcement', {
					type: 'error',
					message: `can't establish connection`,
					detail: error.toString(),
					happen: 'upstream'
				});
			};
			// 切断時
			const upstreamCloseEventHandler = (code: number, desc: string) => {
				emitter(socket, 'announcement', {
					type: 'error',
					message: 'close by upstream',
					detail: desc,
					happen: 'upstream'
				}, true);
			};
			// メッセージ受領 -> クライアントへ返答
			const upstreamMessageEventHandler = (data: WebSocket.IMessage) => {
				// UTF-8 メッセージでなければ処理しない
				if (!(data.type === 'utf8')) {
					return;
				}

				let message: IMessage;
//.........这里部分代码省略.........
开发者ID:sagume,项目名称:Misskey-Web,代码行数:101,代码来源:index.ts

示例8: logInfo

	server.start(() => {
		logInfo(`(cluster: ${cluster.worker.id}) Listening at ${server.info.uri}`);
	});
开发者ID:akionux,项目名称:Misskey-API,代码行数:3,代码来源:server.ts

示例9: function

export default function(endpoint: any, req: any, res: any): void {
	logInfo(`Request: ${req.method} ${req.path}`);

	function reply(data: any): any {
		return res(data).header('Access-Control-Allow-Origin', '*');
	}

	authenticate(req).then((context: any) => {
		if (endpoint.login) {
			const limitKey = endpoint.hasOwnProperty('limitKey') ? endpoint.limitKey : endpoint.name;

			if (endpoint.hasOwnProperty('minInterval')) {
				detectBriefInterval();
			} else if (endpoint.hasOwnProperty('limitDuration') && endpoint.hasOwnProperty('limitMax')) {
				rateLimit();
			} else {
				call();
			}

			// 短い期間の方のリミット
			function detectBriefInterval(): void {
				const minIntervalLimiter = new Limiter({
					id: `${context.user.id}:${endpoint.name}:for-detect-brief-interval`,
					duration: endpoint.minInterval,
					max: 1,
					db: limiterDB
				});

				minIntervalLimiter.get((limitErr, limit) => {
					if (limitErr !== null) {
						return reply({
							error: 'something-happened'
						}).code(500);
					} else if (limit.remaining === 0) {
						return reply({
							error: 'brief-interval-detected'
						}).code(429);
					} else {
						if (endpoint.hasOwnProperty('limitDuration') && endpoint.hasOwnProperty('limitMax')) {
							rateLimit();
						} else {
							call();
						}
					}
				});
			}

			// 長い期間の方のリミット
			function rateLimit(): void {
				const limiter = new Limiter({
					id: `${context.user.id}:${limitKey}`,
					duration: endpoint.limitDuration,
					max: endpoint.limitMax,
					db: limiterDB
				});

				limiter.get((limitErr, limit) => {
					if (limitErr !== null) {
						return reply({
							error: 'something-happened'
						}).code(500);
					} else if (limit.remaining === 0) {
						return reply({
							error: 'rate-limit-exceeded'
						}).code(429);
					} else {
						call();
					}
				});
			}
		} else {
			call();
		}

		function call(): void {
			require(`${__dirname}/rest-handlers/${endpoint.name}`).default(
				context.app, context.user, req, reply, context.isOfficial);
		}
	}, (err: any) => {
		reply({
			error: 'authentication-failed'
		}).code(403);
	});
}
开发者ID:akionux,项目名称:Misskey-API,代码行数:84,代码来源:api-handler.ts


注:本文中的log-cool.logInfo函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。