commons.java subversion repository
sventon subversion web client - http://www.sventon.org |
[show recent changes] | |
Rev: 696 - https://secure.bioinfweb.info/Code/svn/commons.java / trunk / main / info.bioinfweb.commons.core / src / info / bioinfweb / commons / log / ConsoleApplicationLogger.java |
Show File - ConsoleApplicationLogger.java [show properties] |

1 | /* |
2 | * bioinfweb.commons.java - Shared components of bioinfweb projects made available in a Java library |
3 | * Copyright (C) 2008-2011, 2013-2018 Ben Stöver, Sarah Wiechers |
4 | * <http://commons.bioinfweb.info/Java> |
5 | * |
6 | * This file is free software: you can redistribute it and/or modify |
7 | * it under the terms of the GNU Lesser General Public License as published by |
8 | * the Free Software Foundation, either version 3 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This file is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public License |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | package info.bioinfweb.commons.log; |
20 | |
21 | |
22 | |
23 | /** |
24 | * An implementation of {@link ApplicationLogger} that outputs all messages to {@link System#out} and {@link System#err}. |
25 | * <p> |
26 | * {@link #isUseErrorStream()} determines to which stream error messages are written. The default value is {@code true}. All other messages are always written |
27 | * to {@link System#out}. |
28 | * |
29 | * @author Ben Stöver |
30 | * @since 3.2.0 |
31 | */ |
32 | public class ConsoleApplicationLogger extends AbstractApplicationLogger { |
33 | private boolean useErrorStream = true; |
34 | |
35 | |
36 | /** |
37 | * Determines whether error messages received by this logger should be written to {@link System#err} or {@link System#out}. |
38 | * |
39 | * @return {@code true} if error messages are currently written to {@link System#err} or {@code false} if they are written to {@link System#out} instead |
40 | */ |
41 | public boolean isUseErrorStream() { |
42 | return useErrorStream; |
43 | } |
44 | |
45 | |
46 | /** |
47 | * Determines whether error messages received by this logger should be written to {@link System#err} or {@link System#out}. |
48 | * |
49 | * @param useErrorStream Specify {@code true} here if error messages should be written to {@link System#err} or {@code false} if they should be written to |
50 | * {@link System#out}. |
51 | */ |
52 | public void setUseErrorStream(boolean useErrorStream) { |
53 | this.useErrorStream = useErrorStream; |
54 | } |
55 | |
56 | |
57 | @Override |
58 | public void addMessage(ApplicationLoggerMessage message) { |
59 | if (ApplicationLoggerMessageType.ERROR.equals(message.getType())) { |
60 | System.err.println(message); |
61 | } |
62 | else { |
63 | System.out.println(message); |
64 | } |
65 | } |
66 | } |
sventon 2.5.1