This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

File System interaction for an nRF Connect for Desktop application

It would be useful to read and write other local files apart from the default 'logger', say, to maintain separate custom logs for multiple discovered devices.  However modules like 'fs' and 'path' etc. are not directly available from pc-nrfconnect-shared.

Is there a way to achieve this?

Parents
  • Hi,

    The log transports are hardcoded in the logger module. Depending on your needs, you may have to make a parallel log implementation in order to get the logging functionality that you want. The logger module builds on winston.

    I'll register suggestions to the team for exposing more flexible logging options.

    Regards,
    Terje

  • Thank you for the prompt reply Terje,

    It prompted me to try another approach!

    Initially I tried:

    import { logger, getUserDataDir, fs, path } from 'nrfconnect/core';

    or

    import { fs, path } from 'pc-nr-connect-shared';

    but now realise that it should have been:

    import fs from 'fs';
    import path from 'path';
    import { logger, getUserDataDir } from 'nrfconnect/core';
    ...
    const filename = path.join(USER_DATA_DIR, 'test.log');
    logger.info(filename);
    fs.writeFileSync(filename, 'Lorem Ipsum');

    Which now works.

    Apologies - and I hope this may help someone else...

    Alasdair

Reply
  • Thank you for the prompt reply Terje,

    It prompted me to try another approach!

    Initially I tried:

    import { logger, getUserDataDir, fs, path } from 'nrfconnect/core';

    or

    import { fs, path } from 'pc-nr-connect-shared';

    but now realise that it should have been:

    import fs from 'fs';
    import path from 'path';
    import { logger, getUserDataDir } from 'nrfconnect/core';
    ...
    const filename = path.join(USER_DATA_DIR, 'test.log');
    logger.info(filename);
    fs.writeFileSync(filename, 'Lorem Ipsum');

    Which now works.

    Apologies - and I hope this may help someone else...

    Alasdair

Children
Related