本文整理匯總了TypeScript中@asuna-admin/logger.createLogger函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createLogger函數的具體用法?TypeScript createLogger怎麽用?TypeScript createLogger使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了createLogger函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: createLogger
import { put, select, takeLatest } from 'redux-saga/effects';
import * as R from 'ramda';
import _ from 'lodash';
import { RootState } from '@asuna-admin/store';
import { createLogger } from '@asuna-admin/logger';
import { menuProxy } from '@asuna-admin/adapters';
const logger = createLogger('store:menu');
// --------------------------------------------------------------
// Module menuActionTypes
// --------------------------------------------------------------
const menuActionTypes = {
// ACTION: 'module::action'
INIT: 'menu::init',
INIT_SUCCESS: 'menu::init-success',
};
export const isMenuModule = action => action.type.startsWith('menu::') && !action.transient;
// --------------------------------------------------------------
// Module menuActions
// --------------------------------------------------------------
const menuActions = {
init: () => ({ type: menuActionTypes.INIT }),
};
示例2: query
/*
export interface IGraphQLService {
client: ApolloClient<any>;
serverClient: ApolloClient<any>;
query(queryString: string): Promise<any>;
queryT(query: string): Promise<any>;
loadSchemas(): Promise<any>;
}
*/
// --------------------------------------------------------------
// Main
// --------------------------------------------------------------
const logger = createLogger('adapters:graphql');
export class GraphqlAdapter {
public client: ApolloClient<any>;
public serverClient: ApolloClient<any>;
constructor(uri?: string) {
if (uri) {
this.client = new ApolloClient({ uri });
} else {
logger.log('graphql uri not defined, using /graphql for default');
this.client = new ApolloClient({ uri: '/graphql' });
}
this.serverClient = new ApolloClient({ uri: '/s-graphql' });
}
async query(queryString: string) {
示例3: createLogger
import { call, put, select, takeLatest } from 'redux-saga/effects';
import { reduxAction } from 'node-buffs';
import { message } from 'antd';
import * as R from 'ramda';
import { RootState } from './';
import { authActions } from './auth.actions';
import { createLogger } from '@asuna-admin/logger';
import { securityProxy } from '@asuna-admin/adapters';
import { toErrorMessage } from '@asuna-admin/helpers';
const logger = createLogger('store:security');
// --------------------------------------------------------------
// Module actionTypes
// --------------------------------------------------------------
const securityActionTypes = {
// ACTION: 'security::action'
LOAD_ALL_ROLES: 'security::load-all-roles',
LOAD_ALL_ROLES_SUCCESS: 'security::load-all-roles-success',
GET_CURRENT_USER: 'security::get-current-user',
GET_CURRENT_USER_SUCCESS: 'security::get-current-user-success',
UPDATE_PASSWORD: 'security::update-password',
};
const isSecurityModule = action => action.type.startsWith('security::') && !action.transient;
示例4: createLogger
import { AxiosResponse } from 'axios';
import * as R from 'ramda';
import { createLogger } from '@asuna-admin/logger';
import idx from 'idx';
const logger = createLogger('helpers:errors');
interface FormError {
[key: string]: {
errors: {
field: string;
message: string;
}[];
};
}
// TODO move to node-buffs one day :)
export const reduxActionCallbackPromise = (action): Promise<any> =>
new Promise((resolve, reject) => {
const callback = ({ response, error }) => (response ? resolve(response) : reject(error));
action(callback);
});
export type ReduxCallback<T> = (data: { response: T; error: Error }) => void;
export function safeCallback(cb, data) {
try {
if (cb != null) cb(data);
} catch (e) {
logger.warn('callback error', e, { e });
示例5: createLogger
import * as _ from 'lodash';
import { isJson } from '@asuna-admin/helpers';
import { createLogger } from '@asuna-admin/logger';
import { Config } from '@asuna-admin/config';
import { AppContext } from '.';
const logger = createLogger('core:url-rewriter');
export function valueToArrays(value) {
const castToArrays = value =>
isJson(value) ? JSON.parse(value as string) : _.compact(value.split(','));
const images = value ? (_.isArray(value) ? value : castToArrays(value)) : [];
logger.debug('[valueToArrays]', { value, images });
return images;
}
export function valueToUrl(
value,
{
host,
type,
thumbnail,
}: {
host?: string;
type?: 'image' | 'video' | 'attache' | 'file';
thumbnail?: { width?: number; height?: number };
},
) {
if (value) {
const hostPrefix =
host ||
示例6: createLogger
import { message } from 'antd';
import { apiProxy } from '@asuna-admin/adapters';
import { createLogger } from '@asuna-admin/logger';
import { AxiosRequestConfig } from 'axios';
const logger = createLogger('helpers:upload');
export async function getBase64(image): Promise<string | ArrayBuffer | null> {
const reader = new FileReader();
return new Promise((resolve, reject) => {
reader.addEventListener('load', () => (reader.result ? resolve(reader.result) : resolve()));
reader.addEventListener('error', ev => reject(ev));
reader.readAsDataURL(image);
});
}
export function validateFile(file: { type: string; size: number }): boolean {
// console.log(file);
const isImage = ['image/jpeg', 'image/png', 'image/gif'].indexOf(file.type) > -1;
const isLt20M = file.size / 1024 / 1024 < 20;
logger.log('[validateFile]', file, { isImage, isLt20M });
if (!isImage) {
message.error('You can only upload JPG/PNG/GIF file!');
}
if (!isLt20M) {
message.error('Image must smaller than 20MB!');
}
return isImage && isLt20M;
}
export async function upload(
示例7: createLogger
import * as R from 'ramda';
import { message } from 'antd';
import { REHYDRATE } from 'redux-persist';
import { authActions, authActionTypes, isAuthModule } from './auth.actions';
import { appActionTypes, RootState } from './';
import { panesActions } from './panes.actions';
import { routerActions } from './router.redux';
import { createLogger } from '@asuna-admin/logger';
import { authProxy } from '@asuna-admin/adapters';
import { toErrorMessage } from '@asuna-admin/helpers';
import idx from 'idx';
const logger = createLogger('store:auth');
// --------------------------------------------------------------
// Login sagas
// --------------------------------------------------------------
function* loginSaga({ payload: { username, password }, callback }) {
const auth: AuthState = yield select((state: RootState) => state.auth);
try {
const response = yield call(authProxy.login, username, password);
logger.log('[loginSaga]', 'response is', response);
// 切換用戶時更新操作區域,如果未來需要保存當前頁麵配置的話,應該將切換操作提出為單獨的 Saga
if (auth.username !== username) {
yield put(panesActions.closeAll());
}
示例8: createLogger
import { connect, Socket } from 'socket.io-client';
import { appActions } from '@asuna-admin/store';
import { AppContext } from '@asuna-admin/core';
import { createLogger } from '@asuna-admin/logger';
// --------------------------------------------------------------
// Main
// --------------------------------------------------------------
const logger = createLogger('adapters:ws');
export class WsAdapter {
private port?: number;
private namespace: string;
private static io: typeof Socket;
constructor(opts: { port?: number; namespace?: string } = {}) {
this.port = opts.port;
this.namespace = opts.namespace || 'admin';
if (!AppContext.isServer && !WsAdapter.io) {
WsAdapter.io = connect(
'/admin',
{ secure: true, reconnectionDelay: 10e3, reconnectionDelayMax: 60e3 },
);
WsAdapter.io.on('connect', () => {
logger.log('[connect]', { id: WsAdapter.io.id, AppContext });
AppContext.dispatch(appActions.heartbeat());
示例9: createLogger
import { call, put, select, takeLatest } from 'redux-saga/effects';
import { message } from 'antd';
import { reduxAction } from 'node-buffs';
import * as R from 'ramda';
import _ from 'lodash';
import { AxiosResponse } from 'axios';
import { contentActions, RootState } from '@asuna-admin/store';
import { createLogger } from '@asuna-admin/logger';
import { AppContext } from '@asuna-admin/core';
import { ReduxCallback, safeCallback, toErrorMessage } from '@asuna-admin/helpers';
const logger = createLogger('store:models');
// --------------------------------------------------------------
// Module actionTypes
// --------------------------------------------------------------
const modelsActionTypes = {
// ACTION: 'module::action'
FETCH: 'models::fetch',
FETCH_SUCCESS: 'models::fetch-success',
UPSERT: 'models::upsert',
REMOVE: 'models::remove',
LOAD_ALL_SCHEMAS: 'models::load-all-schemas',
LOAD_ALL_SCHEMAS_SUCCESS: 'models::load-all-schemas-success',
};
export const isModelModule = action => action.type.startsWith('models::') && !action.transient;
// --------------------------------------------------------------
示例10: createLogger
import _ from 'lodash';
import * as R from 'ramda';
import idx from 'idx';
import { DynamicFormTypes } from '@asuna-admin/components';
import { castModelKey, castModelName, diff } from '@asuna-admin/helpers';
import { createLogger } from '@asuna-admin/logger';
import { AppContext } from '@asuna-admin/core';
const logger = createLogger('helpers:schema');
export const peek = (message, callback?) => fields => {
if (callback) callback();
logger.log('[peek]', { message, fields });
return fields;
};
export type Fields = {
[key: string]: {
name: string;
ref: string;
type: string;
value?: any;
options: {
name: string;
type: DynamicFormTypes;
label: string | null;
length: number | null;
required: boolean;
selectable?: string;
jsonType?: string;