@@ -28,70 +28,103 @@ var logging = gcloud.logging();
2828// [END setup]
2929
3030// [START listSinks]
31- function listSinks ( callback ) {
31+ /**
32+ * @param {Function } callback Callback function.
33+ */
34+ function listSinksExample ( callback ) {
3235 // list all sinks in the authenticated project
33- logging . getSinks ( callback ) ;
36+ logging . getSinks ( function ( err , sinks ) {
37+ if ( err ) {
38+ return callback ( err ) ;
39+ }
40+
41+ // Should have received all sinks
42+ console . log ( 'Found ' + sinks . length + ' sinks' ) ;
43+ callback ( null , sinks ) ;
44+ } ) ;
3445}
3546// [END listSinks]
3647
3748// [START createSink]
38- function createSink ( callback ) {
39- // Get a reference to the Cloud Storage component
40- var gcs = gcloud . storage ( ) ;
41-
49+ /**
50+ * @param {string } sinkName Name of the new sink.
51+ * @param {Object } config Configuration options for the new sink.
52+ * @param {Function } callback Callback function.
53+ */
54+ function createSinkExample ( sinkName , config , callback ) {
4255 // create a new sink in the authenticated project
4356 //
4457 // This method only works if you are authenticated as yourself, e.g. using the
4558 // gcloud SDK.
46- logging . createSink ( 'mySink' , {
47- destination : gcs . bucket ( 'logging-bucket' )
48- } , callback ) ;
59+ logging . createSink ( sinkName , config , function ( err , sink , apiResponse ) {
60+ if ( err ) {
61+ return callback ( err ) ;
62+ }
63+
64+ // Should have received newly created sink
65+ console . log ( 'Created ' + sinkName , sink ) ;
66+ callback ( null , sink , apiResponse ) ;
67+ } ) ;
4968}
5069// [END createSink]
5170
5271// [START updateSink]
53- function updateSink ( callback ) {
54- // Get a reference to the Cloud Storage component
55- var gcs = gcloud . storage ( ) ;
72+ /**
73+ * @param {string } sinkName Name of the sink to update.
74+ * @param {Object } config New configuration options for the sink.
75+ * @param {Function } callback Callback function.
76+ */
77+ function updateSinkExample ( sinkName , config , callback ) {
5678 // Get a reference to an existing sink
57- var sink = logging . sink ( 'mySink' ) ;
79+ var sink = logging . sink ( sinkName ) ;
5880
5981 // update a sink
6082 //
6183 // This method only works if you are authenticated as yourself, e.g. using the
6284 // gcloud SDK.
63- sink . setMetadata ( {
64- // change destination to something else
65- destination : gcs . bucket ( 'other-logging-bucket' )
66- } , callback ) ;
85+ sink . setMetadata ( config , function ( err , apiResponse ) {
86+ if ( err ) {
87+ return callback ( err ) ;
88+ }
89+
90+ console . log ( 'Updated ' + sinkName ) ;
91+ callback ( null , apiResponse ) ;
92+ } ) ;
6793}
6894// [END updateSink]
6995
7096// [START deleteSink]
71- function deleteSink ( callback ) {
97+ /**
98+ * @param {string } sinkName Name of the sink to delete.
99+ * @param {Function } callback Callback function.
100+ */
101+ function deleteSinkExample ( sinkName , callback ) {
72102 // Get a reference to an existing sink
73- var sink = logging . sink ( 'mySink' ) ;
103+ var sink = logging . sink ( sinkName ) ;
74104
75105 // delete a sink
76106 //
77107 // This method only works if you are authenticated as yourself, e.g. using the
78108 // gcloud SDK.
79- sink . delete ( callback ) ;
109+ sink . delete ( function ( err , apiResponse ) {
110+ if ( err ) {
111+ return callback ( err ) ;
112+ }
113+
114+ console . log ( 'Deleted ' + sinkName ) ;
115+ callback ( null , apiResponse ) ;
116+ } ) ;
80117}
81118// [END deleteSink]
82119
83- exports . runExample = function ( cb ) {
84- listSinks ( function ( err , sinks , apiResponse ) {
85- console . log ( err , 'sinks:' , sinks , 'apiResponse:' , apiResponse ) ;
86- if ( typeof cb === 'function' ) {
87- cb ( err , sinks ) ;
88- }
89- } ) ;
120+ // Run the examples
121+ exports . main = function ( cb ) {
122+ listSinksExample ( cb || console . log ) ;
90123} ;
91- exports . createSink = createSink ;
92- exports . updateSink = updateSink ;
93- exports . deleteSink = deleteSink ;
124+ exports . createSinkExample = createSinkExample ;
125+ exports . updateSinkExample = updateSinkExample ;
126+ exports . deleteSinkExample = deleteSinkExample ;
94127
95128if ( module === require . main ) {
96- exports . runExample ( ) ;
129+ exports . main ( ) ;
97130}
0 commit comments