Unsuppress useful warnings in core. (#248)

This also temporarily removes `coreLogger`'s config from the public API One reason is that we don't have many logs that could benefit from suppressing (see diff) so the experimental API would not be useful to the user yet.

Also, the default config was suppressing useful warnings. Those warnings _would_ have been dead-code-eliminated in production mode anyway, so having a separate config to suppress them in dev mode makes it confusing.

Fixes P-171
This commit is contained in:
Aria 2022-07-07 10:27:21 +02:00 committed by GitHub
parent 88df1ef004
commit a9910fecba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 36 deletions

View file

@ -3,7 +3,6 @@ import ReactDOM from 'react-dom'
import studio from '@theatre/studio'
import {getProject} from '@theatre/core'
import {Scene} from './Scene'
import {TheatreLoggerLevel} from '@theatre/shared/logger'
/**
* This is a basic example of using Theatre for manipulating the DOM.
*
@ -16,13 +15,13 @@ studio.initialize()
ReactDOM.render(
<Scene
project={getProject('Sample project', {
experiments: {
logging: {
internal: true,
dev: true,
min: TheatreLoggerLevel.TRACE,
},
},
// experiments: {
// logging: {
// internal: true,
// dev: true,
// min: TheatreLoggerLevel.TRACE,
// },
// },
})}
/>,
document.getElementById('root'),

View file

@ -61,7 +61,7 @@ export function getProject(id: string, config: IProjectConfig = {}): IProject {
return existingProject.publicApi
}
const rootLogger = _coreLogger(config.experiments)
const rootLogger = _coreLogger()
const plogger = rootLogger.named('Project', id)
if (process.env.NODE_ENV !== 'production') {

View file

@ -66,12 +66,10 @@ export default class Project {
readonly config: Conf = {},
readonly publicApi: TheatreProject,
) {
this._logger = _coreLogger(config.experiments).named('Project', id)
this._logger = _coreLogger({logging: {dev: true}}).named('Project', id)
this._logger.traceDev('creating project')
this.address = {projectId: id}
// remove when logger is understood
this._logger._kapow('this is a "kapow"')
const onDiskStateAtom = new Atom<ProjectState>({
ahistoric: {
ahistoricStuff: '',
@ -136,7 +134,7 @@ export default class Project {
`Project ${this.address.projectId} is already attached to studio ${this._studio.address.studioId}`,
)
} else {
this._logger.warnDev(
console.warn(
`Project ${this.address.projectId} is already attached to studio ${this._studio.address.studioId}`,
)
return

View file

@ -1,10 +1,7 @@
import {privateAPI, setPrivateAPI} from '@theatre/core/privateAPIs'
import Project from '@theatre/core/projects/Project'
import type {ISheet} from '@theatre/core/sheets/TheatreSheet'
import type {
ITheatreLoggerConfig,
ITheatreLoggingConfig,
} from '@theatre/shared/logger'
import type {ProjectAddress} from '@theatre/shared/utils/addresses'
import type {
ProjectId,
@ -23,23 +20,23 @@ export type IProjectConfig = {
* The state of the project, as [exported](https://docs.theatrejs.com/in-depth/#exporting) by the studio.
*/
state?: $IntentionalAny
experiments?: IProjectConfigExperiments
// experiments?: IProjectConfigExperiments
}
export type IProjectConfigExperiments = {
/**
* Defaults to using global `console` with style args.
*
* (TODO: check for browser environment before using style args)
*/
logger?: ITheatreLoggerConfig
/**
* Defaults:
* * `production` builds: console - error
* * `development` builds: console - error, warning
*/
logging?: ITheatreLoggingConfig
}
// export type IProjectConfigExperiments = {
// /**
// * Defaults to using global `console` with style args.
// *
// * (TODO: check for browser environment before using style args)
// */
// logger?: ITheatreLoggerConfig
// /**
// * Defaults:
// * * `production` builds: console - error
// * * `development` builds: console - error, warning
// */
// logging?: ITheatreLoggingConfig
// }
/**
* A Theatre project

View file

@ -145,13 +145,13 @@ export default class Sequence {
this.pause()
if (process.env.NODE_ENV !== 'production') {
if (typeof position !== 'number') {
this._logger.errorDev(
console.error(
`value t in sequence.position = t must be a number. ${typeof position} given`,
)
position = 0
}
if (position < 0) {
this._logger.errorDev(
console.error(
`sequence.position must be a positive number. ${position} given`,
)
position = 0
@ -231,7 +231,7 @@ export default class Sequence {
}
if (range[1] > sequenceDuration) {
this._logger.warnDev(
console.warn(
`Argument conf.range[1] in sequence.play(conf) cannot be longer than the duration of the sequence, which is ${sequenceDuration}s. ${JSON.stringify(
range[1],
)} given.`,

View file

@ -239,7 +239,7 @@ export default class TheatreSequence implements ISequence {
return priv.play(conf)
} else {
if (process.env.NODE_ENV !== 'production') {
priv._logger.warnDev(
console.warn(
`You seem to have called sequence.play() before the project has finished loading.\n` +
`This would **not** a problem in production when using '@theatre/core', since Theatre loads instantly in core mode. ` +
`However, when using '@theatre/studio', it takes a few milliseconds for it to load your project's state, ` +