Skip to content

Instantly share code, notes, and snippets.

@mrister
Last active October 1, 2024 18:52
Show Gist options
  • Save mrister/0640724a2cb56fd97114c9c273226178 to your computer and use it in GitHub Desktop.
Save mrister/0640724a2cb56fd97114c9c273226178 to your computer and use it in GitHub Desktop.
Logging to Loggly in TypeScript
// run npm i -D @types/winston
// run npm i winston
import {Logger, transports} from 'winston';
// run npm i winston-loggly-bulk
require('winston-loggly-bulk');
const logger = new Logger({
transports: [
new transports.Console(),
new transports.Loggly({
token: 'YOUR_TOKEN',
subdomain: 'YOUR_SUBDOMAIN',
json: true,
})
]
});
// define interface to only log a part of data
interface Loggable {
id?: string,
getLog(): string
description?: string
}
const message: Loggable = {
id: 'test',
getLog() {
return 'Hello from TypeScript!!';
}
// there is no description since it is optional
};
// function to use only our Loggable interface
function logMessage (message: Loggable) {
logger.info(message.getLog());
}
// log something
logMessage(message);
@alfasin
Copy link

alfasin commented Oct 1, 2024

I'm getting an error on this line:
https://gist.github.com/mrister/0640724a2cb56fd97114c9c273226178#file-loggly-winston-typescript-ts-L10

saying that Loggly is not recognized in transports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment