Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm super new to React and I'm trying to get it set up for Meteor and piecing stuff together from other sources too. One of these other sources set up console logging for the app, but I'm going the ES6/JSX way so just using their code wouldn't work for me (or it doesn't seem like it does).

Some code I found for logging is

import Logger from 'simple-console-logger';
Logger.configure({level: 'debug'});

but I'm seeing this error cannot find module './dumy'

I also tried using react-logger and react-console-logger to no avail. Here's my code for the latter, which I believe should work.

import {Logger, ConsoleLogger} from 'react-console-logger';
const myLogger = new Logger();
export default class App extends Component {
    render() {
        myLogger.info('something witty');
    }
}

However, myLogger.info('...') is making a call to node_modules/react-console-logger/lib/Logger.js which has it defined as

picture of code since copy-paste doesn't work

And this.logger is undefined, although I see it be defined above?

Does anyone know what I'm doing wrong? It looks to me like the library has it wrong, but maybe it has something to do with me using JSX files instead of js?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
184 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you're just after console logging here's what I'd do:

export default class App extends Component {
  componentDidMount() {
    console.log('I was triggered during componentDidMount')
  }

  render() {
    console.log('I was triggered during render')
    return ( 
      <div> I am the App component </div>
    )
  }
}

Shouldn't be any need for those packages just to do console logging.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...