Yuta HIGUCHI | 02a125e | 2017-05-05 18:36:21 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Yuta HIGUCHI | 02a125e | 2017-05-05 18:36:21 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.cli; |
| 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
| 20 | import java.util.List; |
| 21 | import java.util.stream.Collectors; |
| 22 | |
| 23 | import org.apache.karaf.shell.commands.Argument; |
| 24 | import org.apache.karaf.shell.commands.Command; |
| 25 | import org.apache.karaf.shell.commands.Option; |
| 26 | import org.slf4j.Logger; |
| 27 | |
| 28 | import com.google.common.collect.ImmutableList; |
| 29 | |
| 30 | /** |
| 31 | * CLI command which just log message to ONOS log for ease of debugging, etc. |
| 32 | */ |
| 33 | @Command(scope = "onos", name = "mark", |
| 34 | description = "Mark message in the log") |
| 35 | public class MarkCommand extends AbstractShellCommand { |
| 36 | |
| 37 | private static final String MARK = "--MARK--"; |
| 38 | |
| 39 | @Option(name = "--impersonate", |
| 40 | description = "Logger to use when logging this message", |
| 41 | required = false, multiValued = false) |
| 42 | String loggerName = "org.onosproject.cli.MarkCommand"; |
| 43 | |
| 44 | // TODO Option to specify log level |
| 45 | |
| 46 | |
| 47 | @Argument(index = 0, name = "message", description = "Message to log", |
| 48 | required = false, multiValued = true, valueToShowInHelp = MARK) |
| 49 | List<String> message = ImmutableList.of(MARK); |
| 50 | |
| 51 | @Override |
| 52 | protected void execute() { |
| 53 | |
| 54 | Logger log = getLogger(loggerName); |
| 55 | |
| 56 | log.info("{}", message.stream().collect(Collectors.joining(" "))); |
| 57 | |
| 58 | } |
| 59 | |
| 60 | } |