ファイル情報

Rev. 2d5cda5e9dde331e37d58133b688a8b2c6295345
サイズ 3,972 バイト
日時 2017-09-03 14:40:39
作者 Daigo Moriwaki
ログメッセージ

Merge remote-tracking branch 'origin/master' into wdoor-stable

内容

  1. ## $Id$
  2. ## Copyright (C) 2004 NABEYA Kenichi (aka nanami@2ch)
  3. ## Copyright (C) 2007-2012 Daigo Moriwaki (daigo at debian dot org)
  4. ##
  5. ## This program is free software; you can redistribute it and/or modify
  6. ## it under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2 of the License, or
  8. ## (at your option) any later version.
  9. ##
  10. ## This program is distributed in the hope that it will be useful,
  11. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ## GNU General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with this program; if not, write to the Free Software
  17. ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. require 'kconv'
  19. require 'getoptlong'
  20. require 'thread'
  21. require 'timeout'
  22. require 'socket'
  23. require 'yaml'
  24. require 'yaml/store'
  25. require 'digest/md5'
  26. require 'webrick'
  27. require 'fileutils'
  28. require 'logger'
  29. require 'shogi_server/compatible'
  30. require 'shogi_server/board'
  31. require 'shogi_server/game'
  32. require 'shogi_server/league'
  33. require 'shogi_server/login'
  34. require 'shogi_server/move'
  35. require 'shogi_server/piece'
  36. require 'shogi_server/player'
  37. require 'shogi_server/timeout_queue'
  38. require 'shogi_server/usi'
  39. require 'shogi_server/util'
  40. require 'shogi_server/command'
  41. require 'shogi_server/buoy'
  42. module ShogiServer # for a namespace
  43. Default_Max_Identifier_Length = 32
  44. Default_Timeout = 60 # for single socket operation
  45. Default_Game_Name = "default-1500-0"
  46. Default_Max_Moves = 256
  47. Default_Least_Time_Per_Move = 0
  48. One_Time = 10
  49. Login_Time = 300 # time for LOGIN
  50. Revision = "20170902"
  51. RELOAD_FILES = ["shogi_server/league/floodgate.rb",
  52. "shogi_server/league/persistent.rb",
  53. "shogi_server/pairing.rb"]
  54. BASE_DIR = File.expand_path(File.dirname(__FILE__))
  55. def reload
  56. RELOAD_FILES.each do |f|
  57. load File.join(BASE_DIR, f)
  58. end
  59. end
  60. module_function :reload
  61. class Logger < ::Logger
  62. def initialize(logdev, shift_age = 0, shift_size = 1048576)
  63. super
  64. class << @logdev
  65. def shift_log_period(now)
  66. age_file = age_file_name(now)
  67. move_age_file_in_the_way(age_file)
  68. unless Mkdir.mkdir_for(age_file)
  69. @dev.write("[ERROR] Could not create a directory: %s\n" % [File.dirname(age_file)])
  70. return true
  71. end
  72. @dev.close
  73. rename_file(@filename, age_file)
  74. @dev = create_logfile(@filename)
  75. return true
  76. end
  77. def age_file_name(time)
  78. if RUBY_VERSION >= "2.2.0"
  79. postfix = previous_period_end(time, @shift_age).strftime("%Y%m%d") # YYYYMMDD
  80. else
  81. postfix = previous_period_end(time).strftime("%Y%m%d") # YYYYMMDD
  82. end
  83. age_file = File.join(
  84. File.dirname(@filename),
  85. postfix[0..3], # YYYY
  86. postfix[4..5], # MM
  87. postfix[6..7], # DD
  88. File.basename(@filename))
  89. return age_file
  90. end
  91. def age_file_exists?(age_file)
  92. return FileTest.exist?(age_file)
  93. end
  94. def rename_file(old_file, new_file)
  95. File.rename(old_file, new_file)
  96. end
  97. def move_age_file_in_the_way(age_file)
  98. return unless age_file_exists?(age_file)
  99. now = Time.now
  100. new_file = "%s.%s%06d" % [age_file, now.strftime("%Y%m%d%H%M%S"), now.usec]
  101. @dev.write("[WARN] An existing '#{age_file}' is beeing moved to '#{new_file}'\n")
  102. rename_file(age_file, new_file)
  103. end
  104. end # @logdev
  105. end
  106. end # class Logger
  107. class Formatter < ::Logger::Formatter
  108. def initialize
  109. super
  110. @datetime_format = "%Y-%m-%dT%H:%M:%S"
  111. end
  112. def call(severity, time, progname, msg)
  113. %!%s [%s] %s\n! % [format_datetime(time), severity, msg2str(msg)]
  114. end
  115. end
  116. end # module ShogiServer
旧リポジトリブラウザで表示