How to use the warn function from winston

Find comprehensive JavaScript winston.warn code examples handpicked from public code repositorys.

winston.warn is a method in the Winston logging library for Node.js that allows you to log a warning-level message.

144
145
146
147
148
149
150
151
152
153
accountsController.profile = function(req, res) {
    var user = req.user;
    var backUrl = req.header('Referer') || '/';
    if (_.isUndefined(user)) {
        req.flash('message', 'Permission Denied.');
        winston.warn('Undefined User - /Profile');
        return res.redirect(backUrl);
    }

    var content = {};
fork icon380
star icon2
watch icon5

+ 15 other calls in file

166
167
168
169
170
171
172
173
174
175
accountsController.profile = function (req, res) {
  var user = req.user
  var backUrl = req.header('Referer') || '/'
  if (_.isUndefined(user)) {
    req.flash('message', 'Permission Denied.')
    winston.warn('Undefined User - /Profile')
    return res.redirect(backUrl)
  }

  var content = {}
fork icon380
star icon0
watch icon2

+ 15 other calls in file

How does winston.warn work?

In Winston, the warn method logs a message with severity level "warn" and can include metadata such as the current timestamp and custom data. The logged message will be output to one or more configured transports, such as the console or a file.

185
186
187
188
189
190
191
    && process.env.FACEBOOK_CLIENT_SECRET) {
    const fcma = new FacebookCustomAudiencesAction(process.env.FACEBOOK_CLIENT_ID, process.env.FACEBOOK_CLIENT_SECRET);
    Hub.addAction(fcma);
}
else {
    winston.warn(`[Facebook Custom Audiences] Action not registered because required environment variables are missing.`);
}
fork icon95
star icon47
watch icon68

+ 7 other calls in file

237
238
239
240
241
242
243
244
245
246
            throw e;
        }).then(() => {
            winston.info(`Google Sheets Streamed ${rowCount} rows including headers`, { webhookId: request.webhookId });
            resolve();
        }).catch((e) => {
            winston.warn("End flush failed.", { webhookId: request.webhookId });
            reject(e);
        });
    }
}).on("error", (e) => {
fork icon95
star icon47
watch icon68

+ 19 other calls in file

Ai Example

1
2
3
4
5
6
7
8
const winston = require("winston");

const logger = winston.createLogger({
  level: "warn",
  transports: [new winston.transports.Console()],
});

logger.warn("This is a warning message.");

In this example, we create a new logger with a log level of warn, which means it will only log messages with a severity of warn or higher. We then add a console transport to log messages to the console. Finally, we log a warning message using the warn method of the logger instance. The output in the console will be something like: vbnet Copy code

41
42
43
44
45
46
47
48
49
50
        autoBreadcrumbs: false,
        environment: process.env.ACTION_HUB_BASE_URL,
    }).install();
}
blocked((time, stack) => {
    winston.warn(`Event loop blocked for ${time}ms, operation started here:\n${stack.join("\n")}`);
}, { threshold: 100 });
if (!process.env.ACTION_HUB_BASE_URL) {
    throw new Error("No ACTION_HUB_BASE_URL environment variable set.");
}
fork icon95
star icon47
watch icon68

+ 3 other calls in file

27
28
29
30
31
32
33
34
35
36
if (supportMultiWs) {
    try {
        json = JSON.parse(stateJson);
    }
    catch (e) {
        winston.warn("Received malform JSON for supported multi tenant version. Proceeding as str.");
    }
}
if (supportMultiWs && Array.isArray(json)) {
    this.clients = JSON.parse(stateJson)
fork icon95
star icon47
watch icon68

+ 3 other calls in file

9
10
11
12
13
14
15
16
17
18
const batch = require('../batch');
module.exports = function (Categories) {
  Categories.getRecentReplies = async function (cid, uid, start, stop) {
    // backwards compatibility, treat start as count
    if (stop === undefined && start > 0) {
      winston.warn('[Categories.getRecentReplies] 3 params deprecated please use Categories.getRecentReplies(cid, uid, start, stop)');
      stop = start - 1;
      start = 0;
    }
    let pids = await db.getSortedSetRevRange(`cid:${cid}:pids`, start, stop);
fork icon1
star icon1
watch icon5

+ 4 other calls in file

249
250
251
252
253
254
255
256
257
258
      var content = fs.readFileSync(default_path + name);
      var stats = fs.statSync(default_path + name);
      fs.writeFileSync(user_path + name, content, { mode: stats.mode });
    }
  } catch (e1) {
    logger.warn(`Updater: Missing default controller ${default_path}`);
    return false;
  }
}
return true;
fork icon0
star icon1
watch icon0

+ 5 other calls in file

130
131
132
133
134
135
136
137
138
        r,
        rules[r]['condition'],
        rules[r]['action']
      );
    } catch (e) {
      logger.warn('Cannot import event processing rule.');
    }
  }
}
fork icon0
star icon1
watch icon0

+ 2 other calls in file

29
30
31
32
33
34
35
36
37
38
if (!mongo.port) {
  mongo.port = dbPort;
}
const dbName = mongo.database;
if (dbName === undefined || dbName === "") {
  winston.warn(noDefaultDbName);
  mongo.database = "nodebb";
}

const hosts = mongo.host.split(",");
fork icon0
star icon0
watch icon1

+ 19 other calls in file

741
742
743
744
745
746
747
748
749
750
  file.pipe(fs.createWriteStream(object.filePath))
})

busboy.on('finish', function () {
  if (error) {
    winston.warn(error)
    return res.status(error.status).send(error.message)
  }

  if (_.isUndefined(object.filePath) || _.isUndefined(object.filename)) {
fork icon0
star icon0
watch icon1

+ 203 other calls in file

112
113
114
115
116
117
118
119
120
121
122
    const range = pkg.engines.node;
    const semver = require('semver');
    const compatible = semver.satisfies(version, range);


    if (!compatible) {
        winston.warn('Your version of Node.js is too outdated for NodeBB. Please update your version of Node.js.');
        winston.warn(`Recommended ${chalk.green(range)}, ${chalk.yellow(version)} provided\n`);
    }
}

fork icon0
star icon0
watch icon1

+ 33 other calls in file

256
257
258
259
260
261
262
263
264
265
try {
    size = await image.size(path.join(nconf.get('upload_path'), 'system', 'site-logo-x50.png'));
} catch (err) {
    if (err.code === 'ENOENT') {
        // For whatever reason the x50 logo wasn't generated, gracefully error out
        winston.warn('[logo] The email-safe logo doesn\'t seem to have been created, please re-upload your site logo.');
        size = {
            height: 0,
            width: 0,
        };
fork icon0
star icon0
watch icon1

+ 16 other calls in file

53
54
55
56
57
58
59
60
61
62
} catch (e) {
    // DEPRECATED: @1.15.0, remove in version >=1.17
    // for backwards compatibility
    // if that fails, fall back to `pluginData.library`
    if (pluginData.library) {
        winston.warn(`   [plugins/${pluginData.id}] The plugin.json field "library" is deprecated. Please use the package.json field "main" instead.`);
        winston.verbose(`[plugins/${pluginData.id}] See https://github.com/NodeBB/NodeBB/issues/8686`);

        libraryPath = path.join(pluginData.path, pluginData.library);
        Plugins.libraries[pluginData.id] = require(libraryPath);
fork icon0
star icon0
watch icon1

+ 50 other calls in file

22
23
24
25
26
27
28
29
30
}

if (nconf.get('dep-check') === undefined || nconf.get('dep-check') !== false) {
    await meta.dependencies.check();
} else {
    winston.warn('[init] Dependency checking skipped!');
}

await db.initSessionStore();
fork icon0
star icon0
watch icon1

+ 12 other calls in file

299
300
301
302
303
304
305
306
307
308
309
310
async function createAdmin() {
    const User = require('./user');
    const Groups = require('./groups');
    let password;


    winston.warn('No administrators have been detected, running initial user setup\n');


    let questions = [{
        name: 'username',
        description: 'Administrator username',
fork icon0
star icon0
watch icon1

+ 15 other calls in file

73
74
75
76
77
78
79
80
81
82
            clients.forEach(client => {
                exec(client);
            });
        }
        else {
            if (debug) winston.warn(`Error while listing socketio clients in ${taskId}`, err);
        }
    });
}
function initializeSocketIO(s) {
fork icon0
star icon0
watch icon1