最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to stop Node sequelize logging status - Stack Overflow

programmeradmin0浏览0评论

I'm using npm package sequelize + mysql and then:

let option = {logging: false}

While initializing:

new Sequelize(option)

It works fine for not outputting the query string.

However, it is still outputting the status code after I INSERT or UPDATE the database, and the result look like this: [ undefined, 1 ], [3 , 1](3 is the id, [AffectedID, AffectedRow])

I believe I need to change the cursor settings, but I found none.

I'm following the instructions, so the code is basically very similar to : .html

I'm using the RAW query and here is my query sentence:

.query(query, {
      replacements: parameters,
      type: Sequelize.QueryTypes[qt]
    })

So how can I stop this ? Should I change mysql settings directly or there is a better way ?

EDIT:

I just found out I had a auto-logger and I need to set it to false for insert and update, so thanks for the reply.

I'm using npm package sequelize + mysql and then:

let option = {logging: false}

While initializing:

new Sequelize(option)

It works fine for not outputting the query string.

However, it is still outputting the status code after I INSERT or UPDATE the database, and the result look like this: [ undefined, 1 ], [3 , 1](3 is the id, [AffectedID, AffectedRow])

I believe I need to change the cursor settings, but I found none.

I'm following the instructions, so the code is basically very similar to : http://docs.sequelizejs./manual/usage.html

I'm using the RAW query and here is my query sentence:

.query(query, {
      replacements: parameters,
      type: Sequelize.QueryTypes[qt]
    })

So how can I stop this ? Should I change mysql settings directly or there is a better way ?

EDIT:

I just found out I had a auto-logger and I need to set it to false for insert and update, so thanks for the reply.

Share Improve this question edited Apr 30, 2019 at 7:21 asked Apr 26, 2019 at 20:15 user8379578user8379578 1
  • That doesn't seem like logging but something else. Can you show some code that generates that output? – tadman Commented Apr 26, 2019 at 20:17
Add a ment  | 

4 Answers 4

Reset to default 4

Instantiating sequelize takes in more parameters than just the options object. You need to also pass your database, username, and password before your config options.

const sequelize = new Sequelize('database', 'username', 'password', {
  logging: false
  // rest of your config
});

There another way to stop logging of sequelize query. just add extra key named "logging": false, of your sequelize config file. here is example

{
  "development": {
    "username": "xxx",
    "password": "",
    "database": "xxx",
    "host": "127.0.0.1",
    "dialect": "mysql",
    "operatorsAliases": false,
    "timezone" : "+06:00"
  },
  "test": {
    "username": "xxx",
    "password": "xxx,
    "database": "xxxx",
    "host": "127.0.0.1",
    "dialect": "mysql",
    "timezone" : "+06:00"
  },
  "production": {
    "logging": false,
    "username": "xxxx",
    "password": "xxx",
    "database": "xxx",
    "host": "127.0.0.1",
    "dialect": "mysql",
    "timezone" : "+06:00"
  }
}

Its highly suggested to you to configure logging status from here, by this you can control your logging. cause production database should not showing log but production and test database should to showing log.

Besides @Trevor's answer is a good answer, Changing the logging on runtime cannot be achieved via his answer.

His answer turned off the logging whenever Sequelize instance is created. But what about changing the logging on runtime. Say i want to turn off logging in few cases. To achieve that

const sequelize = new Sequelize('database', 'username', 'password', {
  logging: false
  // rest of your config
});

// your logging is turned off


// Somewhere else you 
sequelize.options.logging = true


// Somewhere else you want logging to be turned off again
sequelize.options.logging = true

Reference From the source.

This behavior is quiet useful while development and run test on your code base. In development you want to see all logs, but in automated testing environment you are mainly interested in test results.

if you need to disable logging for a specific query:

const userProfileByCredentials = await Models.users.findOne({where: {email, password}, logging: false});
发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>