You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.6 KiB

Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package models
  6. import (
  7. "time"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/timeutil"
  10. "xorm.io/xorm"
  11. )
  12. // Mirror represents mirror information of a repository.
  13. type Mirror struct {
  14. ID int64 `xorm:"pk autoincr"`
  15. RepoID int64 `xorm:"INDEX"`
  16. Repo *Repository `xorm:"-"`
  17. Interval time.Duration
  18. EnablePrune bool `xorm:"NOT NULL DEFAULT true"`
  19. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX"`
  20. NextUpdateUnix timeutil.TimeStamp `xorm:"INDEX"`
  21. Address string `xorm:"-"`
  22. }
  23. // BeforeInsert will be invoked by XORM before inserting a record
  24. func (m *Mirror) BeforeInsert() {
  25. if m != nil {
  26. m.UpdatedUnix = timeutil.TimeStampNow()
  27. m.NextUpdateUnix = timeutil.TimeStampNow()
  28. }
  29. }
  30. // AfterLoad is invoked from XORM after setting the values of all fields of this object.
  31. func (m *Mirror) AfterLoad(session *xorm.Session) {
  32. if m == nil {
  33. return
  34. }
  35. var err error
  36. m.Repo, err = getRepositoryByID(session, m.RepoID)
  37. if err != nil {
  38. log.Error("getRepositoryByID[%d]: %v", m.ID, err)
  39. }
  40. }
  41. // ScheduleNextUpdate calculates and sets next update time.
  42. func (m *Mirror) ScheduleNextUpdate() {
  43. if m.Interval != 0 {
  44. m.NextUpdateUnix = timeutil.TimeStampNow().AddDuration(m.Interval)
  45. } else {
  46. m.NextUpdateUnix = 0
  47. }
  48. }
  49. func getMirrorByRepoID(e Engine, repoID int64) (*Mirror, error) {
  50. m := &Mirror{RepoID: repoID}
  51. has, err := e.Get(m)
  52. if err != nil {
  53. return nil, err
  54. } else if !has {
  55. return nil, ErrMirrorNotExist
  56. }
  57. return m, nil
  58. }
  59. // GetMirrorByRepoID returns mirror information of a repository.
  60. func GetMirrorByRepoID(repoID int64) (*Mirror, error) {
  61. return getMirrorByRepoID(x, repoID)
  62. }
  63. func updateMirror(e Engine, m *Mirror) error {
  64. _, err := e.ID(m.ID).AllCols().Update(m)
  65. return err
  66. }
  67. // UpdateMirror updates the mirror
  68. func UpdateMirror(m *Mirror) error {
  69. return updateMirror(x, m)
  70. }
  71. // DeleteMirrorByRepoID deletes a mirror by repoID
  72. func DeleteMirrorByRepoID(repoID int64) error {
  73. _, err := x.Delete(&Mirror{RepoID: repoID})
  74. return err
  75. }
  76. // MirrorsIterate iterates all mirror repositories.
  77. func MirrorsIterate(f func(idx int, bean interface{}) error) error {
  78. return x.
  79. Where("next_update_unix<=?", time.Now().Unix()).
  80. And("next_update_unix!=0").
  81. Iterate(new(Mirror), f)
  82. }
  83. // InsertMirror inserts a mirror to database
  84. func InsertMirror(mirror *Mirror) error {
  85. _, err := x.Insert(mirror)
  86. return err
  87. }