1 /**********************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.logging
;
14 import java
.io
.BufferedWriter
;
15 import java
.io
.FileWriter
;
16 import java
.io
.IOException
;
18 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
22 * Class to log control commands.
25 * @author Bernd Hufmann
27 final public class ControlCommandLogger
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 * The bufferd writer reference
35 private static BufferedWriter fTraceLog
= null;
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
40 private ControlCommandLogger() {
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 * Initializes the logger class and opens the log file with the given parameter.
48 * @param filename - file name of logger output
49 * @param append - true to open log file in append mode else false (overwrite)
51 public static void init(String filename
, boolean append
) {
52 if (fTraceLog
!= null) {
55 fTraceLog
= openLogFile(filename
, append
);
59 * Closes the log file if open.
61 public static void close() {
62 if (fTraceLog
== null) {
69 } catch (IOException e
) {
70 Activator
.getDefault().logWarning("Can't close log file of the trace control", e
); //$NON-NLS-1$
75 * Logs a message to the log file.
76 * @param msg - message (e.g. command or command result) to log
78 @SuppressWarnings("nls")
79 public static void log(String msg
) {
80 long currentTime
= System
.currentTimeMillis();
81 StringBuilder message
= new StringBuilder("[");
82 message
.append(currentTime
/ 1000);
84 message
.append(String
.format("%1$03d", currentTime
% 1000));
87 if (fTraceLog
!= null) {
89 fTraceLog
.write(message
.toString());
92 } catch (IOException e
) {
93 Activator
.getDefault().logError("Can't log message in log file of the tracer control", e
); //$NON-NLS-1$
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
102 * Opens the trace log file with given name in the workspace root directory
103 * @param filename - file name of logger output
104 * @param append - true to open log file in append mode else false (overwrite)
105 * @return the buffer writer class or null if not successful
107 private static BufferedWriter
openLogFile(String filename
, boolean append
) {
108 BufferedWriter outfile
= null;
110 outfile
= new BufferedWriter(new FileWriter(filename
, append
));
111 } catch (IOException e
) {
112 Activator
.getDefault().logError("Can't open log file for logging of tracer control commands: " + filename
, e
); //$NON-NLS-1$
This page took 0.034086 seconds and 5 git commands to generate.