简体   繁体   中英

Ruby On Rails log file name and line number

Right now, I use log4r for logger in Rails to print file name and line number:

======== config/log4r.yml ========

log4r_config:
  # define all loggers:
  loggers:
    - name          : rails
      level         : DEBUG
      trace         : 'true'
      outputters    : 
      - console

  # define all outputters (incl. formatters)
  outputters:
  - type: StdoutOutputter
    name: console
    formatter:
      date_pattern: '%Y-%m-%d %H:%M:%S'
      pattern     : '%d %l %t : %m'
      type        : PatternFormatter

However it prints file path instead of filename, and it's too long:

2015-12-23 18:05:37 INFO /Users/fudy/Workspace/RubyWorkspace/HelloWorld/app/controllers/welcome_controller.rb:3: in `index' : hello

But I want this format:

2015-12-23 18:05:37 INFO welcome_controller.rb:3: hello

Is there any solution?

It doesn't show in the documentation but from looking at the code you can see that you should replace "t" with "T" to get only the file name.

The other option is to implement custom formatting like explained here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM