本文整理汇总了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;
}
示例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();
}
});
示例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}`);
}
}
示例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})`);
}
}
示例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}`);
});
}
示例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);
}
示例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;
//.........这里部分代码省略.........
示例8: logInfo
server.start(() => {
logInfo(`(cluster: ${cluster.worker.id}) Listening at ${server.info.uri}`);
});
示例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);
});
}