Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid transport, must be an object with a log method #12

Open
Fl4m3Ph03n1x opened this issue Mar 13, 2018 · 15 comments
Open

Invalid transport, must be an object with a log method #12

Fl4m3Ph03n1x opened this issue Mar 13, 2018 · 15 comments

Comments

@Fl4m3Ph03n1x
Copy link

I have the following code snippet:

const winston = require("winston");
const logzioWinstonTransport = require("winston-logzio");

const winstonFactory = ({ API_TOKEN }) => {
    
    const loggerOptions = {
        token:  API_TOKEN,
        host:   "listener.logz.io",
        type:   "nodejs"
    };
    
    winston.add( logzioWinstonTransport, loggerOptions );

    return winston;
};

module.exports = winstonFactory;

Upon executing winstonFactory(), I get the following error:

Error: Invalid transport, must be an object with a log method.
at new LegacyTransportStream (/home/ubuntu/workspace/node_modules/winston-transport/legacy.js:17:11)
at DerivedLogger.add (/home/ubuntu/workspace/node_modules/winston/lib/winston/logger.js:277:7)
at Object.winston.(anonymous function) [as add] (/home/ubuntu/workspace/node_modules/winston/lib/winston.js:84:34)
at winstonFactory (/home/ubuntu/workspace/src/deps/winston.js:12:13)
at setupDeps (/home/ubuntu/workspace/src/deps/index.js:4:15)
at setupApp (/home/ubuntu/workspace/src/app.js:5:24)
at Object. (/home/ubuntu/workspace/server.js:2:13)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)

You can also reproduce the said error by dong this simple tutorial:

https://codeburst.io/setting-up-a-nodejs-monitoring-and-error-alert-system-in-a-jiffy-5241a4ef0561

Am I missing somehting or doing something wrong?
Why isn't it working ?


versions:

  "dependencies": {
    "winston": "^3.0.0-rc2",
    "winston-logzio": "^1.0.6"
  }

NODE: 9.8.0

@AlonMiz
Copy link
Contributor

AlonMiz commented Mar 15, 2018

EDIT:
the reason is due to the Winston version. we support v2 of winston.
we haven't looked at v3 yet.

Using V2

This snippet of code works for me.

const winston = require("winston");
const logzioWinstonTransport = require("winston-logzio");

const winstonFactory = ({ API_TOKEN }) => {

    const loggerOptions = {
        token:  API_TOKEN,
        host:   "listener.logz.io",
        type:   "nodejs"
    };

    winston.add( logzioWinstonTransport, loggerOptions );

    return winston;
};

var winstonLogger = winstonFactory({API_TOKEN: 'asd'});
winstonLogger.log('wow')

because you haven't shared the full code,
im guessing you are trying to override the Winston instance,
instead, try to create a new one

const winstonFactory = ({ API_TOKEN }) => {

    const winston = require("winston");
    const logzioWinstonTransport = require("winston-logzio");

    const loggerOptions = {
        token:  API_TOKEN,
        host:   "listener.logz.io",
        type:   "nodejs"
    };

    winston.add( logzioWinstonTransport, loggerOptions );

    return winston;
};

const winstonLogger = winstonFactory({API_TOKEN: 'asd'});
winstonLogger.log('wow');

@Fl4m3Ph03n1x
Copy link
Author

None of the versions work for me and I couldn't say why.

Regardless after trying a couple new examples I am not able to communicate with logzio so I think it's safe to say that the issue was in my code and not with the library.

Closing this ticket and thanks for contesting!

@veken1199
Copy link

@Fl4m3Ph03n1x I think you were using Winston@3 +, Make sure you install Winston@2
had the same issue

@lokimckay
Copy link

lokimckay commented Oct 16, 2018

Downgrading to an older version of winston is not a good solution IMO

I believe the solution is related to the number of arguments the "log" function accepts
(see this comment in another transport repo)

Would a PR for this be accepted?

EDIT: apologies just saw winston 3.x ticket

@Fire-Brand
Copy link

Having the same issue with Winston 3.0.0-rc5 and winston-logzio 3.0.3
(node 9.4.0)

@idohalevi
Copy link
Contributor

@Fire-Brand
Thank you, I'll take a look. Can you attach the debug logs?

@idohalevi idohalevi reopened this Dec 10, 2018
@Fire-Brand
Copy link

@idohalevi From what i've tried, it seems that if i use the example in the README.MD and simply execute that file it does work.

When i tried creating my own module with winston (for custom logging ) and winston-logzio, i've encountered no errors, but logs were not being sent over(couldn't find them on the dashboard).

After playing around a bit it seemed that while my Console transporter was printing the logs in the terminal, the logzioWinstonTransport wasn't being activated, it seems that issue was that my process was exiting too fast for the logs to be sent... After i gave it a small timeout prior to exiting the process, it did got sent an i was able to see my logs.

@idohalevi
Copy link
Contributor

@Fire-Brand
Thanks for the help. We did implement a finish() function that supposed to be called by the logging framework. I will check why the function wasn't called at the end of your program. Can you try closing Winston logger at the end of the run?

@Fire-Brand
Copy link

Just to clarify, i was using process.exit(0); for the purpose of that test, so maybe that's reason why finish() wasn't called?

@idohalevi
Copy link
Contributor

@Fire-Brand
I will run some tests and get back to you. According to their documentation this is how you should close the logger safely.

@CriptoGirl
Copy link

I had to use :
winston.configure({transports: [new winston.transports.File({ filename: 'logfile.log' }) ]});
instead off:
winston.add(winston.transports.File, { filename: 'logfile.log' });

@Katuka
Copy link

Katuka commented Jul 27, 2019

I had to use :
winston.configure({transports: [new winston.transports.File({ filename: 'logfile.log' }) ]});
instead off:
winston.add(winston.transports.File, { filename: 'logfile.log' });

This worked for me. Thanks.

@galaczi
Copy link

galaczi commented Jul 31, 2019

This works too:

winston.add(new winston.transports.File({ filename: 'logfile.log' }));

@MrCartaaa
Copy link

I had to use :
winston.configure({transports: [new winston.transports.File({ filename: 'logfile.log' }) ]});
instead off:
winston.add(winston.transports.File, { filename: 'logfile.log' });

this worked

@arunsingh49
Copy link

I had to use :
winston.configure({transports: [new winston.transports.File({ filename: 'logfile.log' }) ]});
instead off:
winston.add(winston.transports.File, { filename: 'logfile.log' });

worked for me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests